Submission #415332

#TimeUsernameProblemLanguageResultExecution timeMemory
415332meatrowDango Maker (JOI18_dango_maker)C++17
100 / 100
506 ms123844 KiB
// #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MOD = 1e9 + 7; ll binpow(ll a, ll p, int mod = MOD) { ll res = 1; while (p) { if (p & 1) { (res *= a) %= mod; } p >>= 1; (a *= a) %= mod; } return res; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } const int N = 3005; int dp[N][N][3]; char a[N][N]; void solve() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } } vector<int> last(3); for (int s = 0; s < n + m - 1; s++) { last[0] = max({last[0], last[1], last[2]}); for (int i = 0; i < min(n, s + 1); i++) { int j = s - i; if (j < 0 || j >= m) continue; dp[i][j][0] = *max_element(last.begin(), last.end()); if (i && a[i - 1][j] == 'R' && a[i][j] == 'G' && a[i + 1][j] == 'W') dp[i][j][1] = max(last[0], last[1]) + 1; if (j && a[i][j - 1] == 'R' && a[i][j] == 'G' && a[i][j + 1] == 'W') dp[i][j][2] = max(last[0], last[2]) + 1; last = {dp[i][j][0], dp[i][j][1], dp[i][j][2]}; } } cout << *max_element(last.begin(), last.end()) << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; for (int tc = 1; tc <= T; tc++) { // cout << "Case #" << tc << ": "; solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...