Submission #00091
ソースコード
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 | #include<bits/stdc++.h> using namespace std; int main(){ int h,w;cin>>w>>h; vector<vector< int >>a(h+2,vector< int >(w+2,0)); for ( int i=1;i<=h;i++){ for ( int j=1;j<=w;j++){ cin>>a[i][j]; } } vector<vector< int >>s(h+2,vector< int >(w+2,1)); queue<pair< int , int >>q; s[0][0]=0; s[h+1][w+1]=0; q.push(make_pair(0,0)); q.push(make_pair(h+1,w+1)); while (!q.empty()){ int y=q.front().first; int x=q.front().second; q.pop(); if (y%2==1){ if (y-1>=0&&x+1<w+2&&a[y-1][x+1]==0&&s[y-1][x+1]==1){q.push(make_pair(y-1,x+1));s[y-1][x+1]=0;} if (x+1<w+2&&a[y][x+1]==0&&s[y][x+1]==1){q.push(make_pair(y,x+1));s[y][x+1]=0;} if (y+1<h+2&&x+1<w+2&&a[y+1][x+1]==0&&s[y+1][x+1]==1){q.push(make_pair(y+1,x+1));s[y+1][x+1]=0;} if (y-1>=0&&a[y-1][x]==0&&s[y-1][x]==1){q.push(make_pair(y-1,x));s[y-1][x]=0;} if (y+1<h+2&&a[y+1][x]==0&&s[y+1][x]==1){q.push(make_pair(y+1,x));s[y+1][x]=0;} if (x-1>=0&&a[y][x-1]==0&&s[y][x-1]==1){q.push(make_pair(y,x-1));s[y][x-1]=0;} } else { if (y-1>=0&&x-1>=0&&a[y-1][x-1]==0&&s[y-1][x-1]==1){q.push(make_pair(y-1,x-1));s[y-1][x-1]=0;} if (x-1>=0&&a[y][x-1]==0&&s[y][x-1]==1){q.push(make_pair(y,x-1));s[y][x-1]=0;} if (y+1<h+2&&x-1>=0&&a[y+1][x-1]==0&&s[y+1][x-1]==1){q.push(make_pair(y+1,x-1));s[y+1][x-1]=0;} if (y-1>=0&&a[y-1][x]==0&&s[y-1][x]==1){q.push(make_pair(y-1,x));s[y-1][x]=0;} if (y+1<h+2&&a[y+1][x]==0&&s[y+1][x]==1){q.push(make_pair(y+1,x));s[y+1][x]=0;} if (x+1<w+2&&a[y][x+1]==0&&s[y][x+1]==1){q.push(make_pair(y,x+1));s[y][x+1]=0;} } } long long k=0; for ( int i=1;i<=h;i++){ for ( int j=1;j<=w;j++){ if (a[i][j]==1){ if (i%2==1){ if (s[i-1][j+1]==0)k++; if (s[i][j+1]==0)k++; if (s[i+1][j+1]==0)k++; if (s[i-1][j]==0)k++; if (s[i+1][j]==0)k++; if (s[i][j-1]==0)k++; } else { if (s[i-1][j-1]==0)k++; if (s[i][j-1]==0)k++; if (s[i+1][j-1]==0)k++; if (s[i-1][j]==0)k++; if (s[i+1][j]==0)k++; if (s[i][j+1]==0)k++; } } } } /*for(int i=1;i<h+1;i++){ for(int j=1;j<w+1;j++){ cout<<s[i][j]<<" "; } cout<<"\n"; }*/ cout<<k<< "\n" ; } |
ステータス
項目 | データ |
---|---|
問題 | 0003 - イルミネーション (Illumination) |
ユーザー名 | ei2326 |
投稿日時 | 2023-11-13 17:16:34 |
言語 | C++17 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 2632 Byte |
最大実行時間 | 24 ms |
最大メモリ使用量 | 696 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 | 19 ms | 604 KB |
1
|
||||
2012-yo-t5-in2.txt | AC | 22 ms | 696 KB |
2
|
||||
2012-yo-t5-in3.txt | AC | 24 ms | 632 KB |
3
|
||||
2012-yo-t5-in4.txt | AC | 21 ms | 632 KB |
4
|
||||
2012-yo-t5-in5.txt | AC | 22 ms | 640 KB |
5
|