結果
問題 | No.866 レベルKの正方形 |
ユーザー | LayCurse |
提出日時 | 2019-08-16 21:55:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 7,716 bytes |
コンパイル時間 | 2,136 ms |
コンパイル使用メモリ | 203,276 KB |
実行使用メモリ | 816,412 KB |
最終ジャッジ日時 | 2024-09-22 16:10:53 |
合計ジャッジ時間 | 4,856 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | MLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; template<class S, class T> inline S min_L(S a,T b){ return a<=b?a:b; } template<class T> void malloc2d(T ***arr, int x, int y){ int i; (*arr) = (T**)malloc(x*sizeof(T*)); (*arr)[0] = (T*)malloc(x*y*sizeof(T)); for(i=(1);i<(x);i++){ (*arr)[i]=(*arr)[i-1]+y; } } template<class T> void free2d(T **arr){ free(arr[0]); free(arr); } inline void rd(int &x){ int k, m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i, sz=0; for(;;){ i = getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ char f[10]; int m=0, s=0; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } template<class T> struct Grid2d{ T **d, **d_s; int c, **dw, **lf, r, **rg, set_d, set_s, **up; void malloc(const int rr, const int cc){ r = rr; c = cc; set_s = 0; set_d = 0; malloc2d(&d, r, c); } void free(void){ free2d(d); if(set_s){ free2d(d_s); } if(set_d){ free2d(up); free2d(dw); free2d(lf); free2d(rg); } } T*operator[](int a){ return d[a]; } void setSum(void){ int i, j; if(set_s == 0){ set_s = 1; malloc2d(&d_s, r+1, c+1); } for(i=0;i<(r+1);i++){ d_s[i][0] = 0; } for(j=0;j<(c+1);j++){ d_s[0][j] = 0; } for(i=0;i<(r);i++){ for(j=0;j<(c);j++){ d_s[i+1][j+1] = d_s[i][j+1] + d_s[i+1][j] - d_s[i][j] + d[i][j]; } } } void setDir(void){ int i, j; if(set_d == 0){ set_d = 1; malloc2d(&up, r, c); malloc2d(&dw, r, c); malloc2d(&lf, r, c); malloc2d(&rg, r, c); } for(j=0;j<(c);j++){ up[0][j] = 1; } for(i=(1);i<(r);i++){ for(j=0;j<(c);j++){ if(d[i][j]==d[i-1][j]){ up[i][j] = 1 + up[i-1][j]; } else{ up[i][j] = 1 ; } } } for(j=0;j<(c);j++){ dw[r-1][j] = 1; } for(i=r-2;i>=0;i--){ for(j=0;j<(c);j++){ if(d[i][j]==d[i+1][j]){ dw[i][j] = 1 + dw[i+1][j]; } else{ dw[i][j] = 1 ; } } } for(i=0;i<(r);i++){ lf[i][0] = 1; for(j=(1);j<(c);j++){ if(d[i][j]==d[i][j-1]){ lf[i][j] = 1 + lf[i][j-1]; } else{ lf[i][j] = 1 ; } } } for(i=0;i<(r);i++){ rg[i][c-1] = 1; for(j=c-2;j>=0;j--){ if(d[i][j]==d[i][j+1]){ rg[i][j] = 1 + rg[i][j+1]; } else{ rg[i][j] = 1 ; } } } } void setDirMatch(const T v){ int i, j; if(set_d == 0){ set_d = 1; malloc2d(&up, r, c); malloc2d(&dw, r, c); malloc2d(&lf, r, c); malloc2d(&rg, r, c); } for(j=0;j<(c);j++){ if(d[0][j]==v){ up[0][j] =1; } else{ up[0][j] =0; } } for(i=(1);i<(r);i++){ for(j=0;j<(c);j++){ if(d[i][j]==v){ up[i][j] =1 + up[i-1][j]; } else{ up[i][j] =0; } } } for(j=0;j<(c);j++){ if(d[r-1][j]==v){ dw[r-1][j] =1; } else{ dw[r-1][j] =0; } } for(i=r-2;i>=0;i--){ for(j=0;j<(c);j++){ if(d[i][j]==v){ dw[i][j] =1 + dw[i+1][j]; } else{ dw[i][j] =0; } } } for(i=0;i<(r);i++){ if(d[i][0]==v){ lf[i][0] =1; } else{ lf[i][0] =0; } for(j=(1);j<(c);j++){ if(d[i][j]==v){ lf[i][j] =1 + lf[i][j-1]; } else{ lf[i][j] =0; } } } for(i=0;i<(r);i++){ if(d[i][c-1]==v){ rg[i][c-1] =1; } else{ rg[i][c-1] =0; } for(j=c-2;j>=0;j--){ if(d[i][j]==v){ rg[i][j] =1 + rg[i][j+1]; } else{ rg[i][j] =0; } } } } inline T getSum(const int r1, const int c1, const int r2, const int c2){ return d_s[r2+1][c2+1] - d_s[r1][c2+1] - d_s[r2+1][c1] + d_s[r1][c1]; } } ; int X; int Y; int K; char C[2000][2002]; Grid2d<int> g[26]; int main(){ int a, b, c, i, j, k, mn, mx, res=0; rd(X); rd(Y); rd(K); { int Lj4PdHRW; for(Lj4PdHRW=0;Lj4PdHRW<(X);Lj4PdHRW++){ rd(C[Lj4PdHRW]); } } for(i=0;i<(X);i++){ for(j=0;j<(Y);j++){ C[i][j] -= 'a'; } } for(k=0;k<(26);k++){ g[k].malloc(X,Y); for(i=0;i<(X);i++){ for(j=0;j<(Y);j++){ g[k][i][j] = 0; } } } for(i=0;i<(X);i++){ for(j=0;j<(Y);j++){ g[C[i][j]][i][j] = 1; } } for(k=0;k<(26);k++){ g[k].setSum(); } for(i=0;i<(X);i++){ for(j=0;j<(Y);j++){ int FmcKpFmN, Q5VJL1cS, RZTsC2BF, cTE1_r3A, e98WHCEY, xr20shxY; mn = 1; mx =min_L(X-i, Y-j); Q5VJL1cS = mn; e98WHCEY = mx+1; while(Q5VJL1cS < e98WHCEY){ if((Q5VJL1cS + e98WHCEY)%2==0){ cTE1_r3A = (Q5VJL1cS + e98WHCEY) / 2; } else{ cTE1_r3A = (Q5VJL1cS + e98WHCEY - 1) / 2; } c = 0; for(k=0;k<(26);k++){ if(g[k].getSum(i,j,i+cTE1_r3A-1,j+cTE1_r3A-1)){ c++; } } if(c >= K){ e98WHCEY = cTE1_r3A; } else{ Q5VJL1cS = cTE1_r3A + 1; } } a =e98WHCEY; if(a == mx+1){ continue; } RZTsC2BF = a-1; FmcKpFmN = mx; while(RZTsC2BF < FmcKpFmN){ if((RZTsC2BF + FmcKpFmN)%2==0){ xr20shxY = (RZTsC2BF + FmcKpFmN) / 2; } else{ xr20shxY = (RZTsC2BF + FmcKpFmN + 1) / 2; } c = 0; for(k=0;k<(26);k++){ if(g[k].getSum(i,j,i+xr20shxY-1,j+xr20shxY-1)){ c++; } } if(c <= K){ RZTsC2BF = xr20shxY; } else{ FmcKpFmN = xr20shxY - 1; } } b =FmcKpFmN; res += b-a+1; } } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190810-2 // --- original code --- // int X, Y, K; // char C[2000][2002]; // // Grid2d<int> g[26]; // { // int i, j, k, c, res = 0; // int mn, mx, a, b; // // rd(X,Y,K,C(X)); // // rep(i,X) rep(j,Y) C[i][j] -= 'a'; // rep(k,26){ // g[k].malloc(X,Y); // rep(i,X) rep(j,Y) g[k][i][j] = 0; // } // rep(i,X) rep(j,Y) g[C[i][j]][i][j] = 1; // rep(k,26) g[k].setSum(); // // rep(i,X) rep(j,Y){ // mn = 1; // mx = min(X-i, Y-j); // // a = bsearch_min[int, v, mn, mx+1][ // c = 0; // rep(k,26) if(g[k].getSum(i,j,i+v-1,j+v-1)) c++; // ](c >= K); // // if(a == mx+1) continue; // // b = bsearch_max[int, v, a-1, mx][ // c = 0; // rep(k,26) if(g[k].getSum(i,j,i+v-1,j+v-1)) c++; // ](c <= K); // // res += b-a+1; // } // // wt(res); // }