Submission #937910

#TimeUsernameProblemLanguageResultExecution timeMemory
937910kitlixDango Maker (JOI18_dango_maker)C++17
33 / 100
2017 ms137488 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; struct Edge { int to, f, c, rev; }; vector<vector<Edge>> g; vector<int> ptr, dst; void add_edge(int v, int to) { g[v].push_back({to, 0, 1, (int)g[to].size()}); g[to].push_back({v, 0, 0, (int)g[v].size() - 1}); } int s, t; int dfs(int v, int cmin) { if (v == t) return cmin; for (; ptr[v] < (int)g[v].size(); ++ptr[v]) { auto& [to, f, c, rev] = g[v][ptr[v]]; if (c - f < cmin || dst[to] != dst[v] + 1) continue; int delt = dfs(to, cmin); if (delt > 0) { f += delt; g[to][rev].f -= delt; return delt; } } return 0; } bool bfs(int cmin) { queue<int> q; q.push(s); dst.assign(g.size(), INF); dst[s] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (auto& [to, f, c, rev] : g[v]) { if (c - f < cmin || dst[to] != INF) continue; dst[to] = dst[v] + 1; q.push(to); } } return dst[t] != INF; } mt19937 gen(chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now().time_since_epoch()).count()); template <typename T> void shuffle(vector<T>& a) { for (int i = 0; i < a.size(); ++i) swap(a[i], a[gen() % a.size()]); } signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> table(n, vector<int>(m)); for (auto& r : table) { string s; cin >> s; for (int j = 0; j < m; ++j) { if (s[j] == 'R') r[j] = 0; else if (s[j] == 'G') r[j] = 1; else r[j] = 2; } } g.resize(2 * n * m + 2); auto encode = [&](int x, int y) { return x * m + y; }; s = 2 * n * m, t = 2 * n * m + 1; vector<pair<int, int>> edg_to_add; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (table[i][j] == 0) edg_to_add.emplace_back(s, encode(i, j)); else if (table[i][j] == 1) edg_to_add.emplace_back(encode(i, j), n * m + encode(i, j)); else edg_to_add.emplace_back(n * m + encode(i, j), t); if (table[i][j]) continue; if (j + 2 < m && table[i][j + 1] == 1 && table[i][j + 2] == 2) { edg_to_add.emplace_back(encode(i, j), encode(i, j + 1)); edg_to_add.emplace_back(n * m + encode(i, j + 1), n * m + encode(i, j + 2)); } if (i + 2 < n && table[i + 1][j] == 1 && table[i + 2][j] == 2) { edg_to_add.emplace_back(encode(i, j), encode(i + 1, j)); edg_to_add.emplace_back(n * m + encode(i + 1, j), n * m + encode(i + 2, j)); } } } shuffle(edg_to_add); for (auto [v, to] : edg_to_add) add_edge(v, to); int maxflow = 0; while (bfs(1)) { ptr.assign(g.size(), 0); while (int delt = dfs(s, 1)) { maxflow += delt; ptr.assign(g.size(), 0); } } cout << maxflow; }

Compilation message (stderr)

dango_maker.cpp: In instantiation of 'void shuffle(std::vector<_Tp>&) [with T = std::pair<int, int>]':
dango_maker.cpp:107:23:   required from here
dango_maker.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < a.size(); ++i)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...