Submission #874273

#TimeUsernameProblemLanguageResultExecution timeMemory
874273tsumondaiDango Maker (JOI18_dango_maker)C++14
100 / 100
293 ms80344 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define mp make_pair #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, r, l) for(int i = r; i >= l; i--) #define __TIME (1.0 * clock() / CLOCKS_PER_SEC) typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 3000 + 5; const int oo = 1e18, mod = 1e9 + 7; int n, m, k, ans=0, dp[2*N][5]; int a[N][N]; // R G W void process() { foru(tmp, 1, n+m) { memset(dp, 0, sizeof(dp)); int i=1, j=tmp-1, cnt=1; while (i<=n && j>=1) { if (j>m) { i++; j--; continue; } dp[cnt][0]=max(dp[cnt-1][0], max(dp[cnt-1][1], dp[cnt-1][2])); if (a[i][j-1]==0 && a[i][j]==1 && a[i][j+1]==2) dp[cnt][1]=max(dp[cnt-1][0], dp[cnt-1][1])+1; if (a[i-1][j]==0 && a[i][j]==1 && a[i+1][j]==2) dp[cnt][2]=max(dp[cnt-1][0], dp[cnt-1][2])+1; i++; j--; cnt++; } cnt--; ans+=max(dp[cnt][0], max(dp[cnt][1], dp[cnt][2])); //cout << dp[cnt][0] << ' ' << dp[cnt][1] << ' ' << dp[cnt][2] << '\n'; } cout << ans << '\n'; return; } signed main() { cin.tie(0)->sync_with_stdio(false); //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); cin >> n >> m; memset(a, -1, sizeof(a)); foru(i, 1, n) foru(j, 1, m) { char x; cin >> x; if (x == 'R') a[i][j]=0; else if (x=='G') a[i][j]=1; else if (x=='W') a[i][j]=2; } process(); cerr << "Time elapsed: " << __TIME << " s.\n"; return 0; } /* Xét các trường hợp đặc biệt Kiểm tra lại input/output Cố gắng trâu Lật ngược bài toán Calm down and get VOI Stream of thought: dp */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...