Submission #1144023

#TimeUsernameProblemLanguageResultExecution timeMemory
1144023SmuggingSpunDango Maker (JOI18_dango_maker)C++20
33 / 100
1 ms584 KiB
#include<bits/stdc++.h> #define taskname "C" using namespace std; template<class T>void maximize(T& a, T b){ if(a < b){ a = b; } } int n, m; namespace sub1{ void solve(){ vector<int>dp(1 << (n * m), -1); vector<vector<char>>a(n, vector<char>(m)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> a[i][j]; } } auto solve = [&] (auto&& self, vector<vector<bool>>state) -> int{ int mask = 0; for(int i = 0, p = 0; i < n; i++){ for(int j = 0; j < m; j++, p++){ if(state[i][j]){ mask |= 1 << p; } } } int& ans = dp[mask]; if(ans != -1){ return ans; } for(int i = ans = 0; i < n; i++){ for(int j = 0; j + 2 < m; j++){ if(state[i][j] && state[i][j + 1] && state[i][j + 2]){ if(a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W'){ state[i][j] = state[i][j + 1] = state[i][j + 2] = false; maximize(ans, self(self, state) + 1); state[i][j] = state[i][j + 1] = state[i][j + 2] = true; } } } } for(int i = 0; i + 2 < n; i++){ for(int j = 0; j < m; j++){ if(state[i][j] && state[i + 1][j] && state[i + 2][j]){ if(a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W'){ state[i][j] = state[i + 1][j] = state[i + 2][j] = false; maximize(ans, self(self, state) + 1); state[i][j] = state[i + 1][j] = state[i + 2][j] = true; } } } } return ans; }; cout << solve(solve, vector<vector<bool>>(n, vector<bool>(m, true))); } } namespace sub2{ void solve(){ vector<vector<char>>a(n + 1, vector<char>(m + 1)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> a[i][j]; } } vector<vector<int>>g, row(n + 1, vector<int>(m + 1, -1)); for(int i = 1, id = 0; i <= n; i++){ for(int j = 1; j + 1 < m; j++){ if(a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W'){ row[i][j] = g.size(); g.emplace_back(vector<int>()); } } } int id = 0; for(int i = 1; i + 1 < n; i++){ for(int j = 1; j <= m; j++){ if(a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W'){ if(row[i][j] != -1){ g[row[i][j]].emplace_back(id); } if(row[i + 1][j - 1] != -1){ g[row[i + 1][j - 1]].emplace_back(id); } if(j > 2 && row[i + 2][j - 2] != -1){ g[row[i + 2][j - 2]].emplace_back(id); } id++; } } } vector<int>match(id, -1), f(g.size(), -1); vector<bool>in(g.size(), false); int cnt_iter = 0; auto kuhn = [&] (auto&& self, int u) -> bool{ if(f[u] == cnt_iter){ return false; } f[u] = cnt_iter; for(int& v : g[u]){ if(match[v] == -1 || self(self, match[v])){ match[v] = u; return true; } } return false; }; for(bool run = true; run; cnt_iter++){ run = false; for(int i = 0; i < g.size(); i++){ if(!in[i] && kuhn(kuhn, i)){ in[i] = run = true; id--; } } } cout << int(g.size()) + id; } } namespace sub3{ void solve(){ vector<vector<char>>a(n + 2, vector<char>(m + 2, '#')); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> a[i][j]; } } int ans = 0; auto check = [&] (int x, int y, int d){ return a[x][y] == 'G' && (d == 1 ? (a[x][y - 1] == 'R' && a[x][y + 1] == 'W') : (a[x - 1][y] == 'R' && a[x + 1][y] == 'W')); }; auto work = [&] (int _i, int _j){ vector<pair<int, int>>p; while(_i <= n && _j <= m){ p.emplace_back(_i++, _j++); } vector<int>dp(3, 0); for(auto& [x, y] : p){ vector<int>new_dp(3); new_dp[0] = max(max(dp[0], dp[1]), dp[2]); if(check(x, y, 1)){ new_dp[1] = max(dp[0], dp[1]) + 1; } if(check(x, y, 2)){ new_dp[2] = max(dp[0], dp[2]) + 1; } swap(dp, new_dp); } ans += max(max(dp[0], dp[1]), dp[2]); }; for(int j = 1; j <= m; j++){ work(1, j); } for(int i = 2; i <= n; i++){ work(i, 1); } cout << ans; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> m; if(n <= 4 && m <= 4){ sub1::solve(); } else if(n <= 10 && m <= 10){ sub2::solve(); } else{ sub3::solve(); } }

Compilation message (stderr)

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:164:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  164 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...