Submission #1050550

#TimeUsernameProblemLanguageResultExecution timeMemory
1050550vjudge1Dango Maker (JOI18_dango_maker)C++17
100 / 100
152 ms17500 KiB
#include <iostream> #include <fstream> #include <iomanip> #include <vector> #include <set> #include <map> #include <cstring> #include <string> #include <cmath> #include <cassert> #include <ctime> #include <algorithm> #include <sstream> #include <list> #include <queue> #include <deque> #include <numeric> #include <stack> #include <cstdlib> #include <cstdio> #include <iterator> #include <functional> #include <unordered_set> #include <unordered_map> #include <stdio.h> #include <bitset> #include <cstdint> #include <cassert> #include <complex> #include <climits> #include <random> using namespace std; #define ll long long #define pb push_back #define ull unsigned long long #define F first #define S second #define all(v) v.begin(), v.end() #define rall(x) x.rbegin(), (x).rend() #define int long long const ll mod = 1e9 + 7; const int block = 450; const ll LINF = 1e16; const int INF = 1e8; ll add(ll a, ll b){ ll x = a + b; if(x < 0) x += mod; if(x >= mod) x -= mod; return x; } ll mul(ll a, ll b){ return (a * b) % mod; } ll sub(ll x, ll y){ return add(x, -y); } ll binpow(ll a, ll b) { ll res = 1LL; while (b > 0) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } char c[3005][3005]; int dp[3005][2]; int n, m; bool horiz(int i, int j){ if(j + 2 > m) return 0; return ((c[i][j] == 'R') && (c[i][j + 1] == 'G') && (c[i][j + 2] == 'W')); } bool vert(int i, int j){ if(i + 2 > n) return 0; return ((c[i][j] == 'R') && (c[i + 1][j] == 'G') && (c[i + 2][j] == 'W')); } void solve(){ cin >> n >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> c[i][j]; } } int ans = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ dp[j][0] = 0, dp[j][1] = 0; } int j = 1, ii = i; int idx = 0; while(j <= m && ii >= 1){ idx++; dp[idx][0] = max(dp[idx - 1][0], dp[idx - 1][1]) + horiz(ii, j); if(idx >= 3){ dp[idx][1] = max(dp[idx - 1][1], dp[idx - 3][0]) + vert(ii, j); } else dp[idx][1] = dp[idx - 1][1] + vert(ii, j); ii--, j++; } ans += max(dp[idx][0], dp[idx][1]); } for(int j = 2; j <= m; j++){ for(int i = 1; i <= m; i++){ dp[i][0] = 0, dp[i][1] = 0; } int i = n, jj = j; int idx = 0; while(i >= 1 && jj <= m){ idx++; dp[idx][0] = max(dp[idx - 1][0], dp[idx - 1][1]) + horiz(i, jj); if(idx >= 3){ dp[idx][1] = max(dp[idx - 1][1], dp[idx - 3][0]) + vert(i, jj); } else dp[idx][1] = dp[idx - 1][1] + vert(i, jj); i--, jj++; } ans += max(dp[idx][0], dp[idx][1]); } cout << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int xach = 1; //cin >> xach; while(xach--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...