Submission #00129


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<queue>
using namespace std;
typedef struct
{
int x, y;
int de;
}P;
int main()
{
int dx[] = { 0, -1, 0, 1};
int dy[] = { 1, 0, -1, 0};
int sx, sy;
int w, h, cand;
int cndcnt = 0, decnt = 0;
cin >> h >> w >> cand;
queue<P> que;
char field[h + 10][w + 10];
for( int i = 0; i < h; ++i )
{
for( int j = 0; j < w; ++j )
{
cin >> field[i][j];
if( field[i][j] == 'S' )
{
sx = j;
sy = i;
}
}
}
que.push( (P){ sx, sy, 0 } );
while( !que.empty() )
{
P now = que.front();
que.pop();
if( '1' <= field[now.y][now.x] && field[now.y][now.x] <= '9' )
{
if( cndcnt + 1 == field[now.y][now.x] - '0' )
{
++cndcnt;
while( !que.empty() ) que.pop();
if( cndcnt == cand )
{
cout << now.de << endl;
break;
}
}
}
if( field[now.y][now.x] == 'X' ) continue;
for( int i = 0; i < 4; ++i )
{
int tx = now.x + dx[i];
int ty = now.y + dy[i];
if( 0 <= tx && 0 <= ty && w > now.x && h > now.y && field[ty][tx] != cndcnt + '0' && field[ty][tx] != 'X' )
{
if( !( cndcnt + '0' + 1 <= field[ty][tx] && field[ty][tx] <= '9' ) )
field[ty][tx] = cndcnt + '0';
que.push( (P){ tx, ty, now.de + 1 } );
}
}
/*
getchar();
cout << endl;
for( int i = 0; i < h; ++i )
{
for( int j = 0; j < w; ++j )
{
cout << field[i][j];
}
cout << endl;
}
*/
}
}

ステータス

項目 データ
問題 0005 - チーズ(Cheese)
ユーザー名 ei1507
投稿日時 2016-11-09 18:45:49
言語 C++11
状態 Accepted
得点 100
ソースコード長 1801 Byte
最大実行時間 89 ms
最大メモリ使用量 1420 KB

セット

セット 得点 Cases
1 in1 20 / 20 in1.txt
2 in2 20 / 20 in2.txt
3 in3 20 / 20 in3.txt
4 in4 20 / 20 in4.txt
5 in5 20 / 20 in5.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 18 ms 480 KB
1
in2.txt AC 17 ms 460 KB
2
in3.txt AC 20 ms 444 KB
3
in4.txt AC 89 ms 1308 KB
4
in5.txt AC 65 ms 1420 KB
5