Submission #1277358

#TimeUsernameProblemLanguageResultExecution timeMemory
1277358shirokitoDango Maker (JOI18_dango_maker)C++20
33 / 100
1059 ms318096 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 3000 + 24; int n, m; char a[N][N]; bool ok[N][N][2]; vector<int> g[N * N]; int tdfs = 0; int match[N * N], vis[N * N]; int id(int i, int j) { return (i - 1) * m + j; } bool kuhn(int u) { if (vis[u] == tdfs) return 0; vis[u] = tdfs; for (int v: g[u]) { if (match[v] == 0 || kuhn(match[v])) { match[v] = u; return 1; } } return 0; } void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } int cnt_node = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j + 2 <= m && a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W') { ok[i][j][0] = 1; cnt_node++; } if (i + 2 <= n && a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W') { ok[i][j][1] = 1; cnt_node++; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (!ok[i][j][0]) continue; if (ok[i][j][1]) g[id(i, j)].push_back(id(i, j)); if (i - 1 >= 1 && j + 1 <= m && ok[i - 1][j + 1][1]) g[id(i, j)].push_back(id(i - 1, j + 1)); if (i - 2 >= 1 && j + 1 <= m && ok[i - 2][j + 2][1]) g[id(i, j)].push_back(id(i - 2, j + 2)); } } vector<int> id; for (int i = 1; i <= n * m; i++) id.push_back(i); random_shuffle(id.begin(), id.end()); for (int i: id) { tdfs++; kuhn(i); } int cnt_match = 0; for (int i = 1; i <= n * m; i++) { if (match[i] != 0) cnt_match++; } cout << cnt_node - cnt_match << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); int T = 1; // cin >> T; while (T--) { solve(); } }

Compilation message (stderr)

dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:64:19: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations]
   64 |     random_shuffle(id.begin(), id.end());
      |     ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from dango_maker.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:4581:5: note: declared here
 4581 |     random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...