Problem:
砂の城 (Sandcastle)
問題
JOI 君は家族とともに海水浴に来た．さんざん泳いで泳ぎ疲れた JOI 君は，次は砂浜で砂の城を作って遊んだ．しばらくして砂遊びにも飽きると，JOI 君は城を放置してまた海に泳ぎに向かった．
JOI 君が作った城は，砂浜のうちのある長方形の領域に含まれている．この長方形の領域は，東西南北にマス目状に区切られている．各マスは，JOI 君が作った城の一部であるマス (以下，「城マス」と呼ぶ) かそうでないマス (以下，「更地マス」と呼ぶ) のいずれかである．それぞれの城マスには「強度」と呼ばれる 1 以上 9 以下の整数が定まっている．長方形の領域の外縁部，すなわち外側と接しているマスには城マスは存在しない．
やがて潮が満ちてきて，長方形の領域にも波が押し寄せてくるようになった．波が 1 つ押し寄せてくるたびに，城マスのうち次の条件を満たすものはすべて一斉に崩壊して，更地マスに変化する．
条件： 周囲の 8 マス (東西南北および北東，北西，南東，南西方向に隣接するマス) にある更地マスの数が，そのマスの強度の値以上である．
波が引くと，まもなく次の波が押し寄せて来る．
十分多くの波が押し寄せると，城がすべて崩れてしまうか，丈夫な部分だけが残るかして，波が押し寄せてきても 1 つも城マスが崩壊しないような状態に落ち着く．1 つ以上の城マスを崩壊させるような波が押し寄せてくる回数を求めよ．
入力
入力は 1 + H 行からなる．
1 行目には，2 つの整数 H, W (2 ≤ H ≤ 1000, 2 ≤ W ≤ 1000) が空白を区切りとして書かれている．これは，長方形の領域が縦 H 行，横 W 列の H × W 個のマスに区切られていることを表す．長方形の縦方向は南北方向であり，横方向は東西方向である．
続く H 行にはそれぞれ W 文字からなる文字列が書かれており，最初の波が押し寄せてくる前の長方形の領域の状態を表す．H 行のうちの i 行目の左から j 番目の文字 (1 ≤ i ≤ H, 1 ≤ j ≤ W) は，長方形の領域の北から i 行目，西から j 列目のマスが更地マスである場合は '.' (ピリオド) である．城マスである場合は '1', '2', ..., '9' のいずれかであり，そのマスの強度を表す．
長方形の領域の外縁部はすべて更地マスである．すなわち，すべての入力において，1 行目または H 行目の文字と，各行の左から 1 番目または W 番目の文字はすべて '.' である．
与えられる入力データのうち，入力 1 では H ≤ 50, W ≤ 50 を満たす．
出力
1 つ以上の城マスを崩壊させるような波が押し寄せてくる回数を 1 行で出力せよ．
入出力例
入力例 1
5 6
......
.939..
.3428.
.9393.
......
出力例 1
3
入力例 2
10 10
..........
.99999999.
.9.323239.
.91444449.
.91444449.
.91444449.
.91444449.
.91232329.
.99999999.
..........
出力例 2
35
入出力例 1 においては，初めに押し寄せる波で強度 3 の城マスがすべて崩壊し，
......
.9.9..
..428.
.9.9..
......
という状態になる．
次に押し寄せてくる波では強度 2 の城マスが崩壊し，
......
.9.9..
..4.8.
.9.9..
......
という状態になる．
次に押し寄せてくる波では強度 4 の城マスが崩壊し，
......
.9.9..
....8.
.9.9..
......
という状態になる．
これ以降の波が城マスを崩すことはない．よって答えは 3 である．
問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include <string>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
queue<tuple<int, int, int>>Q; int H, W; string S[1009]; vector<pair<int, int>>vec;
int dx[8] = { 1,1,1,0,-1,-1,-1,0 }, dy[8] = { -1,0,1,1,1,0,-1,-1 }; bool used[1009][1009];
int count(int ex, int ey) {
	if (S[ex][ey] == '.')return 0;
	int cnt = 0;
	for (int k = 0; k < 8; k++) {
		if (S[ex + dx[k]][ey + dy[k]] == '.')cnt++;
	}
	return cnt;
}
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++)cin >> S[i];
	for (int i = 1; i < H - 1; i++) {
		for (int j = 1; j < W - 1; j++) {
			if (S[i][j] != '.' && count(i, j) >= (S[i][j] - '0')) {
				Q.push(make_tuple(0, i, j)); vec.push_back(make_pair(i, j)); used[i][j] = true;
			}
		}
	}
	int pro = -1;
	while (!Q.empty()) {
		int ti = get<0>(Q.front()), fx = get<1>(Q.front()), fy = get<2>(Q.front()); Q.pop();
		if (ti != pro) {
			for (int i = 0; i < vec.size(); i++)S[vec[i].first][vec[i].second] = '.'; pro = ti;
			vec.clear();
		}
		for (int i = 0; i < 8; i++) {
			int ex = fx + dx[i], ey = fy + dy[i];
			if (S[ex][ey] != '.' && used[ex][ey] == false && count(ex, ey) >= (S[ex][ey] - '0')) {
				Q.push(make_tuple(ti + 1, ex, ey)); vec.push_back(make_pair(ex, ey)); used[ex][ey] = true;
			}
		}
	}
	cout << pro + 1 << endl;
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 6356
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;

vector<int> dx={-1,0,1},dy={-1,0,1};
int main() {
    int H,W;    
    cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++)cin>>S[i];
    queue<pair<int,int>> Q;
    for(int h=0;h<H;h++){
        for(int w=0;w<W;w++){
            if(S[h][w]=='.')continue;
            int cnt=0;
            for(int y=h-1;y<=h+1;y++){
                for(int x=w-1;x<=w+1;x++){
                    if(y==h&&x==w)continue;
                    if(S[y][x]=='.')cnt++;
                }
            }
            if(cnt>=S[h][w]-'0')Q.push({h,w});
        }
    }
    int an=0;
    while(!Q.empty()){
        queue<pair<int,int>> NQ;
        an++;
        while(!Q.empty()){
            auto [h,w]=Q.front();
            Q.pop();
            S[h][w]='.';
            for(int y=h-1;y<=h+1;y++){
                for(int x=w-1;x<=w+1;x++){
                    if(S[y][x]=='.')continue;
                    int cnt=0;
                    for(int yy=y-1;yy<=y+1;yy++){
                        for(int xx=x-1;xx<=x+1;xx++){
                            if(yy==y&&xx==x)continue;
                            if(S[yy][xx]=='.')cnt++;
                        }
                    }
                    if(S[y][x]-'0'==cnt)NQ.push({y,x});
                }
            }
        }
        swap(Q,NQ);
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 90
memory_kb: 5372
final_rank: 5

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto H=in(),W=in();
	vvll M(H,vll(W,0));
	REP(i,H){
		auto S=in<string>();
		REP(j,W){
			if(S[j]!='.'){
				M[i][j]=(ll)(S[j]-'0');
			}
		}
	}
	queue<ll> Q,R;
	REP(i,H){
		REP(j,W){
			if(M[i][j]==0){
				Q.push(j+i*W);
			}
		}
	}

	auto decrease = [&](ll u,ll v){
		if(M[v][u]==0) return;
		M[v][u]--;
		if(M[v][u]==0){
			R.push(u+v*W);
		}
	};
	ll C=0;
	while(!Q.empty() || !R.empty()){
		while(!Q.empty()){
			auto V=Q.front();
			Q.pop();
			
			auto u=V%W,v=V/W;
			if(u>0){
				decrease(u-1,v);
				if(v>0) decrease(u-1,v-1);
				if(v<H-1) decrease(u-1,v+1);
			}
			if(u<W-1){
				decrease(u+1,v);
				if(v>0) decrease(u+1,v-1);
				if(v<H-1) decrease(u+1,v+1);
			}
			if(v>0) decrease(u,v-1);
			if(v<H-1) decrease(u,v+1);
		}
		if(!R.empty()) C++;
		swap(Q,R);
	}
	out(C);
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 11528
final_rank: 6

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    int res = 0;
    vector<pair<int,int>> v;
    for (int i = 1; i+1 < h; ++i) {
        for (int j = 1; j+1 < w; ++j) {
            if (s[i][j] != '.') v.push_back({i, j});
        }
    }
    while (1) {
        vector<pair<int,int>> clr;

        for (auto &p : v) {
            int x = p.first, y = p.second;
            int cnt = 0;
            for (int i = 0; i < 8; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (s[nx][ny] == '.') cnt += 1;
            }
            if (cnt >= s[x][y]-'0') {
                clr.push_back({x, y});
            }
        }

        if (clr.size()) {
            vector<pair<int,int>> nv;
            for (auto &p : clr) {
                int x = p.first, y = p.second;
                s[x][y] = '.';
            }
            for (auto &p : clr) {
                int x = p.first, y = p.second;
                for (int i = 0; i < 8; ++i) {
                    int nx = x + dx[i];
                    int ny = y + dy[i];
                    if (s[nx][ny] != '.') {
                        nv.push_back({nx, ny});
                    }
                }
            }
            sort(nv.begin(), nv.end());
            nv.erase(unique(nv.begin(), nv.end()), nv.end());
            res += 1;
            swap(v, nv);
        }
        else {
            break;
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 13864
final_rank: 15

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    int res = 0;
    vector<pair<int,int>> v;
    for (int i = 1; i+1 < h; ++i) {
        for (int j = 1; j+1 < w; ++j) {
            if (s[i][j] != '.') v.push_back({i, j});
        }
    }
    while (1) {
        vector<pair<int,int>> clr;

        for (auto &p : v) {
            int x = p.first, y = p.second;
            int cnt = 0;
            for (int i = 0; i < 8; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (s[nx][ny] == '.') cnt += 1;
            }
            if (cnt >= s[x][y]-'0') {
                clr.push_back({x, y});
            }
        }

        if (clr.size()) {
            vector<pair<int,int>> nv;
            for (auto &p : clr) {
                int x = p.first, y = p.second;
                s[x][y] = '.';
                for (int i = 0; i < 8; ++i) {
                    int nx = x + dx[i];
                    int ny = y + dy[i];
                    if (0 <= nx and nx < h and 0 <= ny and ny < w and s[nx][ny] != '.') {
                        nv.push_back({nx, ny});
                    }
                }
            }
            sort(nv.begin(), nv.end());
            nv.erase(unique(nv.begin(), nv.end()), nv.end());
            res += 1;
            swap(v, nv);
        }
        else {
            break;
        }
    }
    cout << res << endl;
}
accuracy: 0.5714285714285714
time_ms: 130
memory_kb: 13344
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(h,w);
    vector<string> A(h);
    in(A);
    vector2d(bool,used,h,w,false);
    vector2d(int,ans,h,w,-1);
    queue<pair<int,int>> next;
    rep(y,h){
        rep(x,w){
            if(A[y][x]=='.'){
                ans[y][x]=0;
                next.push({y,x});
            }
        }
    }
    auto f=[&](int y,int x){
        int cnt=0;
        for(int dy=-1;dy<=1;dy++){
            for(int dx=-1;dx<=1;dx++){
                cnt+=(used[y+dy][x+dx]);
            }
        }
        return (cnt>=(A[y][x]-'0'));
    };
    int y,x;
    while(!next.empty()){
        tie(y,x)=next.front();
        next.pop();
        used[y][x]=true;
        for(int dy=-1;dy<=1;dy++){
            for(int dx=-1;dx<=1;dx++){
                if(y+dy<0||y+dy>=h||x+dx<0||x+dx>=w)continue;
                if(ans[y+dy][x+dx]!=-1)continue;
                if(f(y+dy,x+dx)){
                    ans[y+dy][x+dx]=ans[y][x]+1;
                    next.push({y+dy,x+dx});
                }
            }
        }
    }
    int ansv=0;
    rep(y,h)chmax(ansv,*max_element(all(ans[y])));
    out(ansv);
}
accuracy: 1
time_ms: 60
memory_kb: 9756
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, n) for(int i = int(l); i < int(n); i++)
void chmin(lint &a, lint b){ if(a > b) a = b; }

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) cin >> s[i];
    
    int nami[h][w];
    rep(i, h) rep(j, w) nami[i][j] = -1;
    
    int cnts[h][w];
    queue<pair<int, int>> que;
    rep(i, h) rep(j, w){
        if(s[i][j] == '.') continue;
        
        int cnt = 0;
        for(int dy: {-1, 0, 1}) for(int dx: {-1, 0, 1}){
            if(dy == 0 && dx == 0) continue;
            
            cnt += (s[i + dy][j + dx] == '.');
        }
        
        cnts[i][j] = cnt;
        if(cnt >= s[i][j] - '0'){
            que.push({i, j});
            nami[i][j] = 0;
        }
    }
    
    while(!que.empty()){
        auto top = que.front();
        que.pop();
        int y = top.first;
        int x = top.second;
        
        s[y][x] = '.';
        
        for(int dy: {-1, 0, 1}) for(int dx: {-1, 0, 1}){
            if(dy == 0 && dx == 0) continue;
            
            int ny = y + dy, nx = x + dx;
            if(s[ny][nx] == '.') continue;
            
            cnts[ny][nx]++;
            if(nami[ny][nx] == -1 && cnts[ny][nx] >= s[ny][nx] - '0'){
                que.push({ny, nx});
                nami[ny][nx] = nami[y][x] + 1;
            }
        }
    }
    
    int ans = -1;
    rep(i, h) rep(j, w) ans = max(ans, nami[i][j]);
    
    cout << ans + 1 << endl;
    
//    rep(i, h){
//        rep(j, w){
//            cout << nami[i][j] << (j == w - 1 ? "\n" : " ");
//        }
//    }
}
accuracy: 1
time_ms: 40
memory_kb: 13108
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  int dx[8]={1,1,1,0,0,-1,-1,-1};
  int dy[8]={-1,0,1,-1,1,-1,0,1};
  vector<vector<short>>A(H,vector<short>(W));
  queue<array<int,3>>bfs;
  for(int i=0;i<H;i++){
    char s;
    for(int j=0;j<W;j++){
      cin>>s;
      if(s!='.')A[i][j]=s-'0';
      else bfs.push({i,j,0});
    }
  }
  int ans=0;
  while(bfs.size()){
    int x=bfs.front()[0],y=bfs.front()[1],t=bfs.front()[2];
    ans=max(ans,t);
    bfs.pop();
    for(int i=0;i<8;i++){
      if(x+dx[i]<0||x+dx[i]>=H||y+dy[i]<0||y+dy[i]>=W||A[x+dx[i]][y+dy[i]]==0)continue;
      --A[x+dx[i]][y+dy[i]];
      if(A[x+dx[i]][y+dy[i]]==0){
        bfs.push({x+dx[i],y+dy[i],t+1});
      }
    }
  }
  cout<<ans<<'\n';
}
accuracy: 1
time_ms: 40
memory_kb: 5480
final_rank: 2

code_snippet: #include<iostream>
#include<set>

using namespace std;

char T[1000][1000];

bool Destroyed(int r, int c)
{
	int counter = 0;
	for (int _r = r - 1; _r <= r + 1; _r++)
		for (int _c = c - 1; _c <= c + 1; _c++)
			if ((_r != r || _c != c) && T[_r][_c] == '.')
				counter++;

	return counter >= (T[r][c] - '0');
}

int main()
{
	int H, W;
	cin >> H >> W;
	set<pair<int, int>> nodes;
	for (int r = 0; r < H; r++)
	{
		for (int c = 0; c < W; c++)
		{
			cin >> T[r][c];
			if (T[r][c] == '.')
				nodes.insert(make_pair(r, c));
		}
	}
	int ans = 0;
	while (true)
	{
		set<pair<int, int>> tmp;
		for (auto& node : nodes)
		{
			int r = node.first;
			int c = node.second;
			for (int _r = max(0,r - 1); _r <= min(H - 1,r + 1); _r++)
				for (int _c = max(0,c - 1); _c <= min(W - 1,c + 1); _c++)
					if (T[_r][_c] != '.' && Destroyed(_r, _c))
						tmp.insert(make_pair(_r, _c));
		}
		if (tmp.size() == 0)
			break;
		for (auto& node : tmp)
			T[node.first][node.second] = '.';
		nodes = tmp;
		ans++;
	}
	cout << ans << endl;

	//system("pause");
}
accuracy: 1
time_ms: 130
memory_kb: 5380
final_rank: 9

code_snippet: #include <stdio.h>
#include<iostream>
#include <vector>
#include <queue>
#include <algorithm>
struct Node
{
	int x;
	int y;
	int depth;
};
int w, h;

int table_rm[1001][1001];
int dirx[8] = {-1,0,1,-1,1,-1,0,1};
int diry[8] = { -1,-1,-1,0,0,1,1,1 };

int check(int y, int x)
{
	if (y >= 0 && y < h && x >= 0 && x < w)
		return 1;
	return 0;
}

int main()
{
	std::cin >> h >> w;
	char a;
	Node tmp;
	std::queue<Node> que;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			std::cin >> a;
			if (a == '.')
			{
				tmp.y = i;
				tmp.x = j;
				tmp.depth = 1;
				que.push(tmp);
				table_rm[i][j] = -1;
			}
			else
			{
				table_rm[i][j] = a - '0';
			}
		}
	}
	Node node;
	int ret = 0;
	while (!que.empty())
	{
		node = que.front();
		que.pop();

		for (int i = 0; i < 8; i++)
		{
			int y = node.y + diry[i];
			int x = node.x + dirx[i];
			if (check(y, x) && table_rm[y][x] > 0)
			{
				table_rm[y][x]--;
				if (table_rm[y][x] == 0)
				{
					ret = std::max(ret, node.depth);
					tmp.depth = node.depth + 1;
					tmp.x = x;
					tmp.y = y;
					que.push(tmp);
				}
			}
		}

	}
	std::cout << ret << std::endl;
}
accuracy: 1
time_ms: 50
memory_kb: 7068
final_rank: 3

code_snippet: #include<iostream>
#include<queue>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define puts(x) cout << (x) << "\n"
using namespace std;
char map[1030][1030]; int a[1030][1030], h, w, ans = 0;
queue<pair<int, int>>q1;
signed main() {
	cin >> h >> w;
	for1(i, h)for1(j, w)cin >> map[i][j];
	for (int i = 2; i < h; i++)for (int j = 2; j < w; j++) if (map[i][j] != '.') {
		for (int dv = -1; dv <= 1; dv++)for (int hc = -1; hc <= 1; hc++)a[i][j] += (map[i + dv][j + hc] == '.');
		if (a[i][j] >= map[i][j] - '0')q1.push(mp(1, i * 2000 + j));
	}
	while (q1.size()) {
		int t = q1.front().first, i = q1.front().second / 2000, j = q1.front().second % 2000;
		q1.pop(); ans = t;
		for (int dv = -1; dv <= 1; dv++)for (int hc = -1; hc <= 1; hc++) {
			a[i + dv][j + hc]++;
			if (map[i + dv][j + hc] != '.' && a[i + dv][j + hc] == map[i + dv][j + hc] - '0')q1.push(mp(t + 1, (i + dv) * 2000 + j + hc));
		}
	}
	puts(ans);
}
accuracy: 1
time_ms: 60
memory_kb: 12208
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i< (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int inf = (1<<30);
int h,w;
int dx[8]={-1,0,1,-1,1,-1,0,1};
int dy[8]={-1,-1,-1,0,0,1,1,1};
bool check(int x,int y){
	return x>=0 && y>=0 && x<w &&  y<h;
}
int dp[1000][1000]={};
int main(){
	cin>>h>>w;
	queue<pair<int,int>> zero;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			char a;
			cin>>a;
			if(a=='.'){
				dp[i][j]=-1;
				zero.push(make_pair(i,j));
			}else{
				dp[i][j]=int(a)-int('0');
			}
		}
	}
	int ans=0;
	while(zero.size()>0){
		ans++;
		//cout<<ans<<endl;
		queue<pair<int,int>> zero2;
		while(zero.size()>0){
			pair<int,int> k=zero.front();
			zero.pop();
			
			rep(i,8){
				if(check(k.second+dx[i],k.first+dy[i])){
					dp[k.first+dy[i]][k.second+dx[i]]--;
					if(dp[k.first+dy[i]][k.second+dx[i]]==0){
						zero2.push(make_pair(k.first+dy[i],k.second+dx[i]));
					}
				}
			}
		}
		zero=zero2;
	}
	/*for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cout<<dp[i][j]<<" ";
		}cout<<endl;
	}*/
	cout<<ans-1<<endl;
}
accuracy: 1
time_ms: 180
memory_kb: 7188
final_rank: 13

code_snippet: #include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

char maze[1234][1234]; ll d[1234][1234], vst[1234][1234];
ll dx[8] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	ll n, m, ans = 0; cin >> n >> m;
	rep2(i, n) {
		rep2(j, m) {
			cin >> maze[i][j];
		}
	}
	rep2(i, n) {
		rep2(j, m) {
			rep(k, 8) {
				if (maze[i + dx[k]][j + dy[k]] == '.') { d[i][j]++; }
			}
		}
	}

	typedef pair<ll, ll>P;
	queue<P> que; queue<ll> cnt;
	rep2(i, n) {
		rep2(j, m) {
			if (maze[i][j] != '.') {
				if ((ll)(maze[i][j] - '0') <= d[i][j] && vst[i][j] == 0) {
					que.push(P(i, j)); cnt.push(1); ans = 1; vst[i][j] = 1;
				}
			}
		}
	}

	while (que.size()) {
		P p = que.front(); que.pop();
		ll ok = cnt.front() + 1; cnt.pop();
		maze[p.first][p.second] = '.';

		for (int i = 0; i < 8; i++) {
			ll nx = p.first + dx[i], ny = p.second + dy[i];
			if (maze[nx][ny] != '.') {
				d[nx][ny]++;
				if ((ll)(maze[nx][ny] - '0') <= d[nx][ny] && vst[nx][ny] == 0) {
					que.push(P(nx, ny)); cnt.push(ok); vst[nx][ny] = 1;
					ans = max(ans, ok);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 23656
final_rank: 16

code_snippet: #include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(4);

  int H, W; cin >> H >> W;

  vector<string> v;
  queue<pair<int, int>> q;
  REP(i,H){
    string s; cin >> s;
    v.push_back(s);
    REP(j,W){
      if(s[j] == '.'){
        q.push({i*W+j, 0});
      }
    }
  }

  int mx = 0;
  while(q.size()){
    auto p = q.front();
    q.pop();

    int y = p.first/W, x = p.first%W;
    chmax(mx, p.second);
    for(int i=-1; i<=1; i++){
      for(int j=-1; j<=1; j++){
        int ny = y+i, nx = x+j;
        if(ny >= 0 && ny < H && nx >= 0 && nx < W && v[ny][nx] != '.'){
          if(v[ny][nx] == '1'){
            v[ny][nx] = '.';
            q.push({ny*W+nx, p.second+1});
          }else{
            v[ny][nx] = (char)('0'+((v[ny][nx]-'0') - 1));
          }
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4176
final_rank: 1

code_snippet: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const vector<int> dx = { 1, 1, 1, 0, -1, -1, -1, 0 };
const vector<int> dy = { 1, 0, -1, -1, -1, 0, 1, 1 };
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	vector<pair<int, int> > dels;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (S[i][j] == '.') continue;
			int cnt = 0;
			for (int k = 0; k < 8; ++k) {
				int tx = i + dx[k], ty = j + dy[k];
				if (0 <= tx && tx < H && 0 <= ty && ty < W && S[tx][ty] == '.') {
					++cnt;
				}
			}
			if (cnt >= int(S[i][j] - '0')) {
				dels.push_back(make_pair(i, j));
			}
		}
	}
	int ans = 0;
	while (!dels.empty()) {
		++ans;
		for (pair<int, int> i : dels) {
			S[i.first][i.second] = '.';
		}
		vector<pair<int, int> > ndels;
		for (pair<int, int> i : dels) {
			for (int j = 0; j < 8; ++j) {
				int sx = i.first + dx[j], sy = i.second + dy[j];
				if (!(0 <= sx && sx < H && 0 <= sy && sy < W && S[sx][sy] != '.')) continue;
				int cnt = 0;
				for (int k = 0; k < 8; ++k) {
					int tx = sx + dx[k], ty = sy + dy[k];
					if (0 <= tx && tx < H && 0 <= ty && ty < W && S[tx][ty] == '.') {
						++cnt;
					}
				}
				if (cnt >= int(S[sx][sy] - '0')) {
					ndels.push_back(make_pair(sx, sy));
				}
			}
		}
		sort(ndels.begin(), ndels.end());
		ndels.erase(unique(ndels.begin(), ndels.end()), ndels.end());
		dels = ndels;
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 3932
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

const vector<int> dx = {-1, 0, 1, 1, 1, 0, -1, -1};
const vector<int> dy = {-1, -1, -1, 0, 1, 1, 1, 0};

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int H, W;
    cin >> H >> W;
    char a;
    set<pair<int, int>> filter;
    int count = 0;
    vector<vector<int>> sa(H, vector<int>(W, 0));
    rep(i, H) rep(j, W) {
        cin >> a;
        sa[i][j] = (a == '.' ? 0 : a - '0');
    }

    queue<pair<int, int>> bre, cas;

    rep(i, 1, H - 1) rep(j, 1, W - 1) {
        int s = 0;
        rep(k, 8) if(sa[i + dy[k]][j + dx[k]] < 1) s++;
        if(s >= sa[i][j]) bre.push(make_pair(i, j));
    }
    while(!bre.empty()) {
        count++;
        while(!bre.empty()) {
            auto targ = bre.front();
            sa[targ.first][targ.second] = 0;
            rep(k, 8) {
                if(sa[targ.first + dy[k]][targ.second + dx[k]] > 0)
                    filter.insert(
                        make_pair(targ.first + dy[k], targ.second + dx[k]));
            }
            bre.pop();
        }
        for(auto aa : filter) {
            cas.push(aa);
        }
        filter.clear();

        while(!cas.empty()) {
            int s = 0;
            auto targ = cas.front();
            if(sa[targ.first][targ.second] > 0) {
                rep(k, 8) if(sa[targ.first + dy[k]][targ.second + dx[k]] < 1)
                    s++;
                if(s >= sa[targ.first][targ.second])
                    filter.insert(make_pair(targ.first, targ.second));
            }
            cas.pop();
        }
        for(auto aa : filter) {
            bre.push(aa);
        }
        filter.clear();
    }
    cout << count << endl;
}
accuracy: 1
time_ms: 250
memory_kb: 13564
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

const vector<int> dx = {-1, 0, 1, 1, 1, 0, -1, -1};
const vector<int> dy = {-1, -1, -1, 0, 1, 1, 1, 0};

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int H, W;
    cin >> H >> W;
    char a;
    set<pair<int, int>> filter;
    int count = 0;
    vector<vector<int>> sa(H, vector<int>(W, 0));
    rep(i, H) rep(j, W) {
        cin >> a;
        sa[i][j] = (a == '.' ? 0 : a - '0');
    }

    queue<pair<int, int>> bre, cas;

    rep(i, 1, H - 1) rep(j, 1, W - 1) {
        int s = 0;
        rep(k, 8) if(sa[i + dy[k]][j + dx[k]] < 1) s++;
        if(s >= sa[i][j]) bre.push(make_pair(i, j));
    }
    while(!bre.empty()) {
        count++;
        while(!bre.empty()) {
            auto targ = bre.front();
            sa[targ.first][targ.second] = 0;
            rep(k, 8) {
                if(sa[targ.first + dy[k]][targ.second + dx[k]] > 0)
                    filter.insert(
                        make_pair(targ.first + dy[k], targ.second + dx[k]));
            }
            bre.pop();
        }
        for(auto aa : filter) {
            cas.push(aa);
        }
        filter.clear();

        // rep(i, H) {
        //     rep(j, W) {
        //         if(sa[i][j])
        //             cout << sa[i][j];
        //         else
        //             cout << '.';
        //     }
        //     cout << endl;
        // }

        while(!cas.empty()) {
            int s = 0;
            auto targ = cas.front();
            rep(k, 8) if(sa[targ.first + dy[k]][targ.second + dx[k]] < 1) s++;
            if(s >= sa[targ.first][targ.second])
                filter.insert(make_pair(targ.first, targ.second));
            cas.pop();
        }
        for(auto aa : filter) {
            bre.push(aa);
        }
        filter.clear();
    }
    cout << count << endl;
}
accuracy: 0.5714285714285714
time_ms: 280
memory_kb: 6772
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

const vector<int> dx = {-1, 0, 1, 1, 1, 0, -1, -1};
const vector<int> dy = {-1, -1, -1, 0, 1, 1, 1, 0};

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int H, W;
    cin >> H >> W;
    char a;
    set<pair<int, int>> filter;
    int count = 0;
    vector<vector<int>> sa(H, vector<int>(W, 0));
    rep(i, H) rep(j, W) {
        cin >> a;
        sa[i][j] = (a == '.' ? 0 : a - '0');
    }

    queue<pair<int, int>> bre, cas;

    rep(i, 1, H - 1) rep(j, 1, W - 1) {
        int s = 0;
        rep(k, 8) if(sa[i + dy[k]][j + dx[k]] < 1) s++;
        if(s >= sa[i][j]) bre.push(make_pair(i, j));
    }
    while(!bre.empty()) {
        count++;
        while(!bre.empty()) {
            auto targ = bre.front();
            sa[targ.first][targ.second] = 0;
            rep(k, 8) {
                if(sa[targ.first + dy[k]][targ.second + dx[k]] > 0)
                    cas.push(
                        make_pair(targ.first + dy[k], targ.second + dx[k]));
            }
            bre.pop();
        }
        while(!cas.empty()) {
            int s = 0;
            auto targ = cas.front();
            rep(k, 8) if(sa[targ.first + dy[k]][targ.second + dx[k]] < 1) s++;
            if(s >= sa[targ.first][targ.second])
                filter.insert(make_pair(targ.first, targ.second));
            cas.pop();
        }
        for(auto aa : filter) {
            bre.push(aa);
        }
        filter.clear();
    }
    cout << count << endl;
}
accuracy: 0.5714285714285714
time_ms: 160
memory_kb: 6868
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int h, w;
int fld[1001][1001];
int sea[1001][1001];
queue<P> que[2];
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

bool wave(bool flag) {
	if(que[flag].empty()) return 0;
	while(!que[flag].empty()) {
		P p = que[flag].front();
		que[flag].pop();
		rep(i, 8) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			sea[ny][nx]++;
			if(fld[ny][nx] != 0 && fld[ny][nx] == sea[ny][nx]) {
				que[!flag].push(P(nx, ny));
			}
		}
	}
	return 1;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	cin >> h >> w;
	rep(i, h) {
		string s;
		cin >> s;
		rep(j, w) {
			if(s[j] == '.') fld[i][j] = 0;
			else fld[i][j] = s[j] - '0';
		}
	}

	REP(i, 1, h-1) {
		REP(j, 1, w-1) {
			rep(d, 8) {
				int nx = j + dx[d];
				int ny = i + dy[d];
				if(fld[ny][nx] == 0) sea[i][j]++;
			}
			if(fld[i][j] != 0 && sea[i][j] >= fld[i][j]) {
				que[0].push(P(j, i));
			}
		}
	}

	int ans = 0;
	bool f = 0;
	while(wave(f)) {
		f = !f;
		ans++;
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 18852
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr ll INF = 1LL<<60;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vector<bool> > used(h, vector<bool>(w));
    vector<vector<int> > cnt(h, vector<int>(w));
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    queue<P> que[2];
    for(int i=1;i<h-1;i++){
        for(int j=1;j<w-1;j++){
            if(s[i][j] == '.') continue;
            for(int di=-1;di<=1;di++)for(int dj=-1;dj<=1;dj++){
                int ni = i+di, nj = j+dj;
                if(s[ni][nj] == '.') cnt[i][j]++;
            }
            if(cnt[i][j] >= s[i][j]-'0'){
                que[0].push(P(i,j));
            }
        }
    }
    bool update = true;
    int t = 0;
    while(update){
        update = false;
        while(!que[0].empty()){
            auto p = que[0].front();
            que[0].pop();
            int i = p.first, j = p.second;
            if(s[i][j] == '.') continue;
            if(used[i][j]) continue;
            if(cnt[i][j] >= s[i][j]-'0'){
                que[1].push(P(i,j));
                used[i][j] = true;
                update = true;
            }
        }
        while(!que[1].empty()){
            auto p = que[1].front();
            que[1].pop();
            int i = p.first, j = p.second;
            s[i][j] = '.';
            for(int di=-1;di<=1;di++)for(int dj=-1;dj<=1;dj++){
                int ni = i+di, nj = j+dj;
                if(s[ni][nj] == '.') continue;
                if(used[ni][nj]) continue;
                cnt[ni][nj]++;
                if(cnt[ni][nj] >= s[ni][nj]-'0') que[0].push(P(ni,nj));
            }
        }
        if(update) t++;
    }
    cout << t << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 8164
final_rank: 7