Submission #00068
ソースコード
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include<bits/stdc++.h> #define all(v) v.begin(),v.end() using namespace std; long long h,w,g[105][105],t[105][105]={},ans=0; bool seen[510][510]={}; void dfs( int H, int W, int h, int w) { const int x1[10]={0,1,1,1,0,-1}; const int y1[10]={-1,-1,0,1,1,0}; const int x2[10]={0,1,0,-1,-1,-1}; const int y2[10]={-1,0,1,1,0,-1}; seen[H][W] = true ; for ( int dir = 0; dir < 6; ++dir) { int nh = H; int nw = W; if (nh%2==1){ nh+=y1[dir]; nw+=x1[dir]; } else { nh+=y2[dir]; nw+=x2[dir]; } if (nh <= 0 || nh > h || nw <= 0 || nw > w) continue ; if (g[nh][nw] == 1) continue ; if (seen[nh][nw]) continue ; dfs(nh, nw,h,w); } } void dfs2( int H, int W, int h, int w) { const int x1[10]={0,1,1,1,0,-1}; const int y1[10]={-1,-1,0,1,1,0}; const int x2[10]={0,1,0,-1,-1,-1}; const int y2[10]={-1,0,1,1,0,-1}; seen[H][W] = false ; for ( int dir = 0; dir < 6; ++dir) { int nh = H; int nw = W; if (nh%2==1){ nh+=y1[dir]; nw+=x1[dir]; } else { nh+=y2[dir]; nw+=x2[dir]; } if (nh <= 0) continue ; if (nh > h) continue ; if (nw <= 0) continue ; if (nw > w) continue ; if (g[nh][nw] == 1) continue ; if (!seen[nh][nw]) continue ; dfs2(nh, nw,h,w); } } int main(){ int x1[6]={0,1,1,1,0,-1}; int y1[6]={-1,-1,0,1,1,0}; int x2[6]={0,1,0,-1,-1,-1}; int y2[6]={-1,0,1,1,0,-1}; cin>>w>>h; for ( int i=1;i<=h;i++){ for ( int j=1;j<=w;j++){ cin>>g[i][j]; } } for ( int i=1;i<=h;i++){ for ( int j=1;j<=w;j++){ int c=0; for ( int k=0;k<6;k++){ if (g[i+y1[k]][j+x1[k]]!=1 && g[i][j]==1 && i%2==1){ t[i+y1[k]][j+x1[k]]++; c++; } if (g[i+y2[k]][j+x2[k]]!=1 && g[i][j]==1 && i%2==0){ t[i+y2[k]][j+x2[k]]++; c++; } } if (g[i][j]==0){ dfs(i,j,h,w); } } } for ( int i=1;i<=h;i++){ for ( int j=1;j<=w;j++){ if (i==1 || i==h || j==1 || j==w ){ if (g[i][j]!=1) dfs2(i,j,h,w); } } } for ( int i=0;i<=h+1;i++){ for ( int j=0;j<=w+1;j++){ if (!seen[i][j]) ans+=t[i][j]; } } cout<<ans<<endl; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 0003 - イルミネーション (Illumination) |
ユーザー名 | r1910 |
投稿日時 | 2020-12-08 18:29:45 |
言語 | C++14 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 2815 Byte |
最大実行時間 | 29 ms |
最大メモリ使用量 | 2104 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | 入力1 | 20 / 20 | *1.txt |
2 | 入力2 | 20 / 20 | *2.txt |
3 | 入力3 | 20 / 20 | *3.txt |
4 | 入力4 | 20 / 20 | *4.txt |
5 | 入力5 | 20 / 20 | *5.txt |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
2012-yo-t5-in1.txt | AC | 29 ms | 604 KB |
1
|
||||
2012-yo-t5-in2.txt | AC | 18 ms | 1432 KB |
2
|
||||
2012-yo-t5-in3.txt | AC | 20 ms | 1184 KB |
3
|
||||
2012-yo-t5-in4.txt | AC | 19 ms | 2104 KB |
4
|
||||
2012-yo-t5-in5.txt | AC | 20 ms | 1968 KB |
5
|