제출 #222999

#제출 시각아이디문제언어결과실행 시간메모리
222999AutoratchDango Maker (JOI18_dango_maker)C++14
13 / 100
5 ms512 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3001; int m,n; char c[N][N]; int v[N][N],h[N][N],vv[N][N],hh[N][N],dp[N][N],eh[N][N],ev[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> m >> n; for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) cin >> c[i][j]; for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) { if(i>2 and c[i-2][j]=='R' and c[i-1][j]=='G' and c[i][j]=='W') v[i][j] = 1; if(j>2 and c[i][j-2]=='R' and c[i][j-1]=='G' and c[i][j]=='W') h[i][j] = 1; eh[i][j] = h[i][j],ev[i][j] = v[i][j]; vv[i][j] = v[i][j]+vv[i-1][j]; v[i][j]+=v[i][j-1]; if(i>=3 and j>=3) v[i][j] = max(v[i][j],eh[i][j]+eh[i-1][j]+eh[i-2][j]+v[i][j-1]); hh[i][j] = h[i][j]+hh[i][j-1]; h[i][j]+=h[i-1][j]; if(i>=3 and j>=3) h[i][j] = max(h[i][j],ev[i][j]+ev[i][j-1]+ev[i][j-2]+h[i-1][j]); if(ev[i][j] and eh[i][j]) v[i][j]--,h[i][j]--; if(ev[i][j-1] and eh[i-1][j]) v[i][j]--,h[i][j]--; if(i>1 and j>1 and ev[i][j-2] and eh[i-2][j]) v[i][j]--,h[i][j]--; int ver = v[i][j],hor = h[i][j]; if(i>=3) ver+=dp[i-3][j]; if(j>=3) hor+=dp[i][j-3]; ver = max(ver,vv[i][j]+dp[i][j-1]); hor = max(hor,hh[i][j]+dp[i-1][j]); dp[i][j] = max(ver,hor); /* cout << i << ' ' << j << endl; cout << v[i][j] << ' ' << vv[i][j] << ' ' << h[i][j] << ' ' << hh[i][j] << endl; cout << dp[i][j] << endl; */ } cout << dp[m][n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...