Submission #1045497

#TimeUsernameProblemLanguageResultExecution timeMemory
1045497juicyT-Covering (eJOI19_covering)C++17
100 / 100
71 ms11784 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; int n, m; vector<vector<int>> a; vector<vector<bool>> spec, vis; bool inside(int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; a = vector(n, vector<int>(m)); vis = spec = vector(n, vector<bool>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a[i][j]; } } int k; cin >> k; long long res = 0; while (k--) { int s, t; cin >> s >> t; spec[s][t] = 1; res += a[s][t]; } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (!vis[i][j] && spec[i][j]) { queue<array<int, 2>> q; vector<int> cands; q.push({i, j}); vis[i][j] = 1; int cnt = 0; while (q.size()) { auto [x, y] = q.front(); q.pop(); if (!spec[x][y]) { cands.push_back(a[x][y]); } else { ++cnt; } for (int dr = 0; dr < 4; ++dr) { int u = x + dx[dr], v = y + dy[dr]; if (inside(u, v) && !vis[u][v] && (spec[x][y] || spec[u][v])) { vis[u][v] = 1; q.push({u, v}); } } } if (cands.size() < 3 * cnt) { cout << "No"; exit(0); } swap(cands.back(), *min_element(cands.begin(), cands.end())); res += accumulate(cands.begin(), cands.begin() + 3 * cnt, 0LL); } } } cout << res; return 0; }

Compilation message (stderr)

covering.cpp: In function 'int main()':
covering.cpp:62:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |                 if (cands.size() < 3 * cnt) {
      |                     ~~~~~~~~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...