RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00706

Natjecanje

설명

Dino has been practicing for a package delivery competition for weeks. In the
competition, the winner is the contestant who delivers all the packages from the
warehouse to the designated destinations the fastest. Unfortunately, Dino has only
two hands, so he can carry at most two packages at a time.
He can drop and pick up packages however he wants, as long as he carries at most
two at a time. He can also carry and deliver them in any order, and each package
can be delivered to any destination. After completing his delivery route, there
must be a package at each of the \(k\) destinations.
During the competition, Dino moves on a grid of \(n\) rows and \(m\) columns, where
free cells are marked with ".", obstacles with "#", Dino’s starting cell and all packages with "S", and
package destinations with "X". In one second, he can move to any adjacent cell in the four directions (up,
down, left, or right) that is not an obstacle. Dropping and picking up packages takes negligible time.
Help Dino determine the minimum number of seconds he needs to deliver all packages to their destinations
and return to the starting cell, or print -1 if it is impossible.

제약
입력 형식

In the first line, there are three natural numbers \(n\), \(m\), and \(k\) (\(1 \le n\), \(m \le 500\), \(1 \le k \le 67\)), the number of
rows and columns of the matrix and the number of package destinations.
In each of the next \(n\) lines, there are \(m\) characters \(c_{ij}\) describing the board. Each character of the matrix
will be one of ".", "#", "S", or "X" (without quotes).
The letter "X" will appear exactly \(k\) times in the matrix.

출력 형식

In the first line, print a single number - the minimum number of seconds required for Dino to deliver all
the packages to their destinations and return to the starting cell, \(or -1\) if this is impossible.

서브태스크
서브태스크점수설명

1

17점

\(k = 2\)

2

26점

\(k \le 16\)

3

29점

\(k \le 22\)

4

38점

No additional constraints.

예제 1
입력
5 5 3
X...X
.....
.....
.....
S...X
출력
24
예제 2
입력
5 5 4
..X..
#X#..
#...X
.SX#.
.....
출력
16
설명

Clarification of the first example: Dino will go with 1 package to the bottom-right destination, leave
the package, and return to the cell with the letter S. Then he will take 2 packages and visit the top-right
destination and the top-left destination. After that, he will return to the starting cell and finish his route
in 24 seconds.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 2

평가 및 의견

Natjecanje

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Natjecanje

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8