Submission #69667526
Source Code Expand
//#include "atcoder/modint" #pragma GCC optimize("Ofast") #include "atcoder/all" #include <bits/stdc++.h> #include <string> using namespace std; using namespace atcoder; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } //const int MOD =1e9+7; //constexpr int MOD =10; constexpr int MOD =998244353; const long long M1=167772161,M2=469762049,M3=1224736769; //const int MOD =31607; using mint = static_modint<MOD>; //using mint = double; //using mint = modint; ostream& operator << (ostream& ost, const mint& m){ost << m.val();return ost;} istream& operator >> (istream& ost, mint& m){int a;ost >> a;m=a;return ost;} double time_limit = 100.0,start_temp=0.01,end_temp=0.0; std::mt19937 rng(std::random_device{}()); signed main(){ //ios_base::sync_with_stdio(false); //cin.tie(NULL); int h,w; cin>>h>>w; string s[h]; int c[h][w],ans=0; vector<pair<int,int>> v; for(int i=0;i<h;i++)cin>>s[i]; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ c[i][j]=0; if(s[i][j]=='#')ans++; if(i!=0&&s[i-1][j]=='#')c[i][j]++; if(i!=h-1&&s[i+1][j]=='#')c[i][j]++; if(j!=0&&s[i][j-1]=='#')c[i][j]++; if(j!=w-1&&s[i][j+1]=='#')c[i][j]++; if(s[i][j]!='#'&&c[i][j]==1)v.push_back({i,j}); } } while(!v.empty()){ vector<pair<int,int>> nv,vx; for(auto p:v){ int i=p.first,j=p.second; //cerr<<p.first<<" "<<p.second<<endl; if(c[i][j]!=1)continue; vx.push_back({i,j}); } for(auto p:vx){ int i=p.first,j=p.second; s[i][j]='#'; ans++; if(i!=0){ c[i-1][j]++; if(s[i-1][j]!='#'&&c[i-1][j]==1)nv.push_back({i-1,j}); } if(i!=h-1){ c[i+1][j]++; if(s[i+1][j]!='#'&&c[i+1][j]==1)nv.push_back({i+1,j}); } if(j!=0){ c[i][j-1]++; if(s[i][j-1]!='#'&&c[i][j-1]==1)nv.push_back({i,j-1}); } if(j!=w-1){ c[i][j+1]++; if(s[i][j+1]!='#'&&c[i][j+1]==1)nv.push_back({i,j+1}); } } v=nv; } cout<<ans<<endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Ulam-Warburton Automaton |
User | yatuba |
Language | C++ 20 (gcc 12.2) |
Score | 425 |
Code Size | 2465 Byte |
Status | AC |
Exec Time | 20 ms |
Memory | 11868 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 425 / 425 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 1 ms | 3592 KiB |
00_sample_01.txt | AC | 1 ms | 3520 KiB |
00_sample_02.txt | AC | 1 ms | 3688 KiB |
01_test_00.txt | AC | 12 ms | 9636 KiB |
01_test_01.txt | AC | 4 ms | 4708 KiB |
01_test_02.txt | AC | 5 ms | 4856 KiB |
01_test_03.txt | AC | 9 ms | 7300 KiB |
01_test_04.txt | AC | 14 ms | 11036 KiB |
01_test_05.txt | AC | 11 ms | 7004 KiB |
01_test_06.txt | AC | 11 ms | 6972 KiB |
01_test_07.txt | AC | 10 ms | 6504 KiB |
01_test_08.txt | AC | 16 ms | 11600 KiB |
01_test_09.txt | AC | 16 ms | 11868 KiB |
01_test_10.txt | AC | 9 ms | 6596 KiB |
01_test_11.txt | AC | 10 ms | 6752 KiB |
01_test_12.txt | AC | 10 ms | 7072 KiB |
01_test_13.txt | AC | 10 ms | 6956 KiB |
01_test_14.txt | AC | 11 ms | 7300 KiB |
01_test_15.txt | AC | 11 ms | 7556 KiB |
01_test_16.txt | AC | 12 ms | 7948 KiB |
01_test_17.txt | AC | 13 ms | 8980 KiB |
01_test_18.txt | AC | 14 ms | 10192 KiB |
01_test_19.txt | AC | 16 ms | 11208 KiB |
01_test_20.txt | AC | 12 ms | 6136 KiB |
01_test_21.txt | AC | 12 ms | 6056 KiB |
01_test_22.txt | AC | 10 ms | 6136 KiB |
01_test_23.txt | AC | 9 ms | 6036 KiB |
01_test_24.txt | AC | 9 ms | 6332 KiB |
01_test_25.txt | AC | 9 ms | 6336 KiB |
01_test_26.txt | AC | 9 ms | 6572 KiB |
01_test_27.txt | AC | 11 ms | 7420 KiB |
01_test_28.txt | AC | 15 ms | 6916 KiB |
01_test_29.txt | AC | 20 ms | 9064 KiB |
01_test_30.txt | AC | 13 ms | 7512 KiB |
01_test_31.txt | AC | 12 ms | 7360 KiB |
01_test_32.txt | AC | 14 ms | 7844 KiB |
01_test_33.txt | AC | 13 ms | 7596 KiB |
01_test_34.txt | AC | 13 ms | 7560 KiB |
01_test_35.txt | AC | 14 ms | 8632 KiB |
01_test_36.txt | AC | 15 ms | 6076 KiB |