Submission #00145
ソースコード
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 | #include<bits/stdc++.h> using namespace std; typedef struct { int x,y; }P; int dx[4]={-1,0,1,0}; int dy[4]={0,-1,0,1}; char maze[1010][1010]; long long int d[1010][1010]; int main(){ int h,w,sx,sy,n,count=0,point=1,stri,strj,total=0,f=0; cin >> h >> w >> n; for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ cin >> maze[i][j]; if (maze[i][j] == 'S' ){ sy=i; sx=j; } } } /* for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cout << maze[i][j] << " "; } cout << endl; }*/ for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ d[i][j]=-1; } } queue<P>que; que.push((P){sx,sy}); d[sy][sx]=0; while (!que.empty()){ P p=que.front(); que.pop(); int x=p.x; int y=p.y; if (maze[y][x] >= '1' && maze[y][x] <= '9' ){ count++; point++; } if ( n-count == 0){ stri=y; strj=x; break ; } f=0; for ( int i=0;i<4;i++){ int nx=x+dx[i]; int ny=y+dy[i]; if (nx>=0 && nx<w && ny>=0 && ny<h && maze[ny][nx] != 'X' && d[ny][nx] == -1 && maze[ny][nx]- '0' <= point || maze[ny][nx] == '.' ){ d[ny][nx]=d[y][x]+1; if (maze[ny][nx] >= '1' && maze[ny][nx] <= '9' ){ f++; } que.push((P){nx,ny}); } } if (f != 0){ total+=d[y][x]; } f=0; } for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ cout << d[i][j] << " " ; } cout << endl; } cout << total << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - チーズ(Cheese) |
ユーザー名 | ei1612 |
投稿日時 | 2016-11-09 18:59:35 |
言語 | C++11 |
状態 | Wrong Answer |
得点 | 0 |
ソースコード長 | 1530 Byte |
最大実行時間 | 8000 ms |
最大メモリ使用量 | 65536 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | in1 | 0 / 20 | in1.txt |
2 | in2 | 0 / 20 | in2.txt |
3 | in3 | 0 / 20 | in3.txt |
4 | in4 | 0 / 20 | in4.txt |
5 | in5 | 0 / 20 | in5.txt |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
in1.txt | WA | 24 ms | 2528 KB |
1
|
||||
in2.txt | MLE | 8000 ms | 65536 KB |
2
|
||||
in3.txt | MLE | 8000 ms | 65536 KB |
3
|
||||
in4.txt | MLE | 8000 ms | 65536 KB |
4
|
||||
in5.txt | MLE | 8000 ms | 65536 KB |
5
|