Submission #00112
ソースコード
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 | #include<bits/stdc++.h> using namespace std; int h,w,n,sx,sy; char city[1001][1001]; int mas[1001][1001]; int mx[4]={0,0,1,-1}; int my[4]={1,-1,0,0}; int slv( int x, int y, int g); typedef pair< int , int > P; main(){ cin>>h>>w>>n; for ( int i=0;i<h;i++){ for ( int j=0;j<w;j++){ cin>>city[i][j]; if (city[i][j]== 'S' ){ sy=i; sx=j; } } } int ans=0; for ( int i=1;i<=n;i++){ memset (mas,0, sizeof (mas)); ans+=slv(sx,sy,i); } cout<<ans<<endl; } int slv( int x, int y, int g){ queue< int > que; que.push(y); que.push(x); int block; while (1){ int ny=que.front(); que.pop(); int nx=que.front(); que.pop(); if (city[ny][nx]== '0' +g){ sy=ny; sx=nx; break ; } block=0; for ( int i=0;i<4;i++){ int dy=ny+my[i]; int dx=nx+mx[i]; if (city[dy][dx]== 'X' || dy<0 || dx<0 || dy>=h || dx>=w || mas[dy][dx]!=0) continue ; que.push(dy); que.push(dx); mas[dy][dx]=mas[ny][nx]+1; } } return mas[sy][sx]; } |
ステータス
項目 | データ |
---|---|
問題 | 0005 - チーズ(Cheese) |
ユーザー名 | ei1541 |
投稿日時 | 2016-11-09 18:03:02 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 1072 Byte |
最大実行時間 | 87 ms |
最大メモリ使用量 | 5472 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 | 4572 KB |
1
|
||||
in2.txt | AC | 23 ms | 4684 KB |
2
|
||||
in3.txt | AC | 17 ms | 4676 KB |
3
|
||||
in4.txt | AC | 87 ms | 5300 KB |
4
|
||||
in5.txt | AC | 66 ms | 5472 KB |
5
|