Logo
(追記) (追記ここまで)

6016번 - Shipping Around an Island 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB371133.333%

문제

Farmer John decided to start his own cruise ship line! He has but one ship, but is hoping for big growth. He recently acquired a map of the area of ocean where his cruise ship will operate. It looks something like the diagram below, with height H (3 <= H <= 1000) and width W (3 <= W <= 1000).

 ...................
 ...................
 .....A.............
 .....A..x..........
 ..x..A.....AAAA....
 .....A.....A..A....
 .....AAAAAAAA.A....
 ........A.....A....
 .xx...AAA...x.A....
 ......A............
 ...AAAAAAAAAAAAA...
 ...................

In this map, '.' denotes water; 'A' is an element of the main island; and 'x' are other islands.

Farmer John has decided his cruise ship will loop around the main island. However, due to trade restrictions, the path his ship takes is NOT allowed to go around any OTHER islands. For instance, the following path of length 50 is not allowed because it encloses the island denoted by 'x'.

 ...................
 ....+--+...........
 ....|A.|...........
 ....|A.|x.+-----+..
 ..x.|A.+--+AAAA.|..
 ....|A.....A..A.|..
 ....|AAAAAAAA.A.|..
 ....|...A.....A.|..
 .xx.|.AAA...x.A.|.. <--- route circumnavigates 'x' -- illegal!
 ..+-+.A.........|..
 ..|AAAAAAAAAAAAA|..
 ..+-------------+..

Given a map, help Farmer John determine the shortest path his cruise ship can take to go around the main island without going around any other islands.

Two cells are considered connected if they lie vertically or horizontally across from one another (not diagonally). It is guaranteed that the main island is connected and that a solution exists.

Note that FJ's path may visit the same square more than once, for instance there are three squares that are visited more than once in FJ's optimal path (of length 62) for the example:

 ...................
 ....+--+...........
 ....|A.|...........
 ....|A.|x.+----+...
 ..x.|A.+--+AAAA|...
 ....|A.....A..A|...
 ....|AAAAAAAA.A|...
 ....|...A..+-+A|...
 .xx.|.AAA..|x|A|...
 ..+-+.A....+-+-++..
 ..|AAAAAAAAAAAAA|..
 ..+-------------+..

The above diagram is somewhat unclear because of the path overlapping itself. Drawn in two stages, FJ's optimal path is:

 ................... ...................
 ................... ....+--+...........
 .....A............. ....|A.|...........
 .....A..x.......... ....|A.|x.+----+...
 ..x..A.....AAAA.... ..x.|A.+--+AAAA|...
 .....A.....A..A.... and then ....|A.....A..A|...
 .....AAAAAAAA.A.... ....|AAAAAAAA.A|...
 ....V...A..+>.A.... ....V...A...>+A|...
 .xx.|.AAA..|x.A.... .xx...AAA...x|A|...
 ..+-+.A....+----+.. .....A.......+-+...
 ..|AAAAAAAAAAAAA|.. ...AAAAAAAAAAAAA...
 ..+-------------+.. ...................

입력

  • Line 1: Two space-separated integers: H and W
  • Lines 2..H+1: Line i+1 contains contains W characters that are the elements of map row i (all '.' or 'x' or 'A')

출력

  • Line 1: The minimum length of a path that Farmer John's cruise ship can take

제한

예제 입력 1

12 19
...................
...................
.....A.............
.....A..x..........
..x..A.....AAAA....
.....A.....A..A....
.....AAAAAAAA.A....
........A.....A....
.xx...AAA...x.A....
......A............
...AAAAAAAAAAAAA...
...................

예제 출력 1

62

힌트

출처

Olympiad > USA Computing Olympiad > 2009-2010 Season > USACO January 2010 Contest > Gold 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /