Submission #1103802

#TimeUsernameProblemLanguageResultExecution timeMemory
1103802arvindr9Dango Maker (JOI18_dango_maker)C++14
100 / 100
227 ms162620 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__) #else #define DEBUG(...) 6 #endif template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";} template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr> ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";} template<typename T> void debug(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";} template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}} typedef int int2; #define int long long #define pi pair<int, int> #define vi vector<int> #define vii vector<vector<int>> #define vpi vector<pi> #define lep(i,l,r) for(int i=l;i<=r;++i) #define rep(i,r,l) for(int i=r;i>=l;--i) #define pb push_back #define mp make_pair #define eb emplace_back #define f first #define s second const int inf = 1e18; int t; typedef array<int,2> a2; int2 main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<string> a(n); lep(i,0,n-1) { cin >> a[i]; } vector<vector<a2>> dp(n, vector<a2>(m)); vector<vector<bool>> can0(n, vector<bool>(m)); // horiz vector<vector<bool>> can1 = can0; // vertical lep(i,0,n-1) { rep(j,m-1,0) { if (j + 2 < m and a[i][j] == 'R' and a[i][j+1] == 'G' and a[i][j+2] == 'W') can0[i][j] = true; if (i + 2 < n and a[i][j] == 'R' and a[i+1][j] == 'G' and a[i+2][j] == 'W') can1[i][j] = true; if (i == 0 or j == m - 1) { // base case if (can0[i][j]) dp[i][j][0] = 1; if (can1[i][j]) dp[i][j][1] = 1; } else { int dp0 = dp[i-1][j+1][0]; // horizontal if (can0[i][j]) { dp0 = max(dp0, 1LL); // place a horizontal thing here dp0 = max(dp0, 1 + dp[i-1][j+1][0]); // place horizontal thing earlier // place vertical thing 3 earlier if (i-3 >= 0 and j+3 < m) { dp0 = max(dp0, 1 + dp[i-3][j+3][1]); } } int dp1 = dp[i-1][j+1][1]; if (can1[i][j]) { dp1 = max(dp1, 1LL); // place a vertical thing here. no restrictions on others dp1 = max(dp1, 1 + max(dp[i-1][j+1][0], dp[i-1][j+1][1])); } dp[i][j][0] = dp0; dp[i][j][1] = dp1; } } } DEBUG(can1[0][3], can1[1][2]); DEBUG(dp[0][3]); DEBUG(dp[1][2]); DEBUG(dp[1][2][1]); int ans = 0; lep(i,0,n-1) { lep(j,0,m-1) { if (j == 0 or i == n-1) { int to_add = max(dp[i][j][0], dp[i][j][1]); DEBUG(i,j,to_add); ans += max(dp[i][j][0], dp[i][j][1]); } } } cout << ans << "\n"; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

Compilation message (stderr)

dango_maker.cpp: In function 'int2 main()':
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
    8 | #define DEBUG(...) 6
      |                    ^
dango_maker.cpp:80:5: note: in expansion of macro 'DEBUG'
   80 |     DEBUG(can1[0][3], can1[1][2]);
      |     ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
    8 | #define DEBUG(...) 6
      |                    ^
dango_maker.cpp:81:5: note: in expansion of macro 'DEBUG'
   81 |     DEBUG(dp[0][3]);
      |     ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
    8 | #define DEBUG(...) 6
      |                    ^
dango_maker.cpp:82:5: note: in expansion of macro 'DEBUG'
   82 |     DEBUG(dp[1][2]);
      |     ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
    8 | #define DEBUG(...) 6
      |                    ^
dango_maker.cpp:83:5: note: in expansion of macro 'DEBUG'
   83 |     DEBUG(dp[1][2][1]);
      |     ^~~~~
dango_maker.cpp:8:20: warning: statement has no effect [-Wunused-value]
    8 | #define DEBUG(...) 6
      |                    ^
dango_maker.cpp:89:17: note: in expansion of macro 'DEBUG'
   89 |                 DEBUG(i,j,to_add);
      |                 ^~~~~
dango_maker.cpp:88:21: warning: unused variable 'to_add' [-Wunused-variable]
   88 |                 int to_add = max(dp[i][j][0], dp[i][j][1]);
      |                     ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...