結果
問題 | No.348 カゴメカゴメ |
ユーザー | latte0119 |
提出日時 | 2016-02-27 12:45:00 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 111 ms / 2,000 ms |
コード長 | 1,910 bytes |
コンパイル時間 | 1,733 ms |
コンパイル使用メモリ | 149,452 KB |
実行使用メモリ | 120,764 KB |
最終ジャッジ日時 | 2023-08-25 02:41:39 |
合計ジャッジ時間 | 6,897 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
39,632 KB |
testcase_01 | AC | 4 ms
9,088 KB |
testcase_02 | AC | 93 ms
63,016 KB |
testcase_03 | AC | 69 ms
14,560 KB |
testcase_04 | AC | 4 ms
9,356 KB |
testcase_05 | AC | 4 ms
9,344 KB |
testcase_06 | AC | 4 ms
9,076 KB |
testcase_07 | AC | 3 ms
9,028 KB |
testcase_08 | AC | 4 ms
9,012 KB |
testcase_09 | AC | 4 ms
9,024 KB |
testcase_10 | AC | 4 ms
9,040 KB |
testcase_11 | AC | 4 ms
9,104 KB |
testcase_12 | AC | 6 ms
10,868 KB |
testcase_13 | AC | 4 ms
9,448 KB |
testcase_14 | AC | 4 ms
9,056 KB |
testcase_15 | AC | 111 ms
120,764 KB |
testcase_16 | AC | 4 ms
9,312 KB |
testcase_17 | AC | 4 ms
9,172 KB |
testcase_18 | AC | 4 ms
9,024 KB |
testcase_19 | AC | 4 ms
8,992 KB |
testcase_20 | AC | 4 ms
9,044 KB |
testcase_21 | AC | 4 ms
9,024 KB |
testcase_22 | AC | 4 ms
9,080 KB |
testcase_23 | AC | 76 ms
32,028 KB |
testcase_24 | AC | 75 ms
30,940 KB |
testcase_25 | AC | 75 ms
30,160 KB |
testcase_26 | AC | 76 ms
31,804 KB |
testcase_27 | AC | 74 ms
29,036 KB |
testcase_28 | AC | 76 ms
33,504 KB |
testcase_29 | AC | 74 ms
30,112 KB |
testcase_30 | AC | 75 ms
31,416 KB |
testcase_31 | AC | 72 ms
28,412 KB |
testcase_32 | AC | 74 ms
31,456 KB |
testcase_33 | AC | 10 ms
11,636 KB |
testcase_34 | AC | 10 ms
11,292 KB |
testcase_35 | AC | 9 ms
11,344 KB |
testcase_36 | AC | 10 ms
11,412 KB |
testcase_37 | AC | 9 ms
11,416 KB |
testcase_38 | AC | 10 ms
11,504 KB |
testcase_39 | AC | 10 ms
11,640 KB |
testcase_40 | AC | 10 ms
11,456 KB |
testcase_41 | AC | 10 ms
10,836 KB |
testcase_42 | AC | 10 ms
11,344 KB |
testcase_43 | AC | 5 ms
9,396 KB |
testcase_44 | AC | 4 ms
9,212 KB |
testcase_45 | AC | 4 ms
9,220 KB |
testcase_46 | AC | 5 ms
9,396 KB |
testcase_47 | AC | 4 ms
9,364 KB |
testcase_48 | AC | 4 ms
9,388 KB |
testcase_49 | AC | 5 ms
9,300 KB |
testcase_50 | AC | 4 ms
9,364 KB |
testcase_51 | AC | 5 ms
9,516 KB |
testcase_52 | AC | 5 ms
9,320 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //#define int long long typedef long long ll; typedef pair<int,int>pint; typedef vector<int>vint; typedef vector<pint>vpint; #define pb push_back #define mp make_pair #define fi first #define se second #define all(v) (v).begin(),(v).end() #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;} template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;} int dy[8]={0,-1,0,1,-1,-1,1,1}; int dx[8]={-1,0,1,0,-1,1,-1,1}; int H,W; string fld[1111]; int N; vint nex[111111]; int sz[111111]; vint G[111111]; int paint(int y,int x,char f,char t,int d,int p){ if(fld[y][x]!=f){ if(fld[y][x]=='x'){ nex[p].pb(y*W+x); fld[y][x]='y'; } return 0; } fld[y][x]=t; int ret=1; rep(i,d){ int ny=y+dy[i],nx=x+dx[i]; if(ny<0||ny>=H||nx<0||nx>=W)continue; ret+=paint(ny,nx,f,t,d,p); } return ret; } void build(int v,int y,int x){ rep(i,nex[v].size()){ int yy=nex[v][i]/W,xx=nex[v][i]%W; if(fld[yy][xx]!='y')continue; sz[N]=paint(yy,xx,'y','.',8,114514); G[v].pb(N); N++; paint(yy,xx,'.','@',4,N-1); build(N-1,yy,xx); } } int dp0[111111],dp1[111111]; void solve(int v){ dp0[v]=0;dp1[v]=sz[v]; rep(i,G[v].size()){ int to=G[v][i]; solve(to); dp0[v]+=max(dp0[to],dp1[to]); dp1[v]+=dp0[to]; } } signed main(){ cin.tie(0); ios_base::sync_with_stdio(false); cin>>H>>W; H+=2;W+=2; reps(i,1,H-1)cin>>fld[i],fld[i]="."+fld[i]+"."; fld[0]=fld[H-1]=string(W,'.'); N=1; paint(0,0,'.','@',4,0); build(0,0,0); solve(0); cout<<dp0[0]<<endl; return 0; }