Submission #1049601

#TimeUsernameProblemLanguageResultExecution timeMemory
1049601vjudge1T-Covering (eJOI19_covering)C++17
100 / 100
68 ms16548 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 2; vector<vector<int>> a; vector<int> xet; vector<vector<bool>> check, dem, red; int n, m, q, x[N], y[N]; int ans = 0, tmp = 0, tmp1 = 0; int xx[] = {-1, -2, -1, 0, 1, 2, 1, 0, -1, 0, 1, 0}, yy[] = {-1, 0, 1, 2, 1, 0, -1, -2, 0, 1, 0, -1}; bool in(int u, int v) { if(u < 0 || v < 0 || u >= n || v >= m) return false; return true; } void dfs(int u, int v) { tmp += a[u][v]; tmp1++; check[u][v] = true; for(int i = 8; i < 12; i++) { if(in(u + xx[i], v + yy[i]) && !dem[u + xx[i]][v + yy[i]] && !red[u + xx[i]][v + yy[i]]) { dem[u + xx[i]][v + yy[i]] = true; xet.push_back(a[u + xx[i]][v + yy[i]]); } } for(int i = 0; i < 8; i++) { if(in(u + xx[i], v + yy[i]) && !check[u + xx[i]][v + yy[i]] && red[u + xx[i]][v + yy[i]]) dfs(u + xx[i], v + yy[i]); } } int main () { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n >> m; a.resize(n + 2); check.resize(n + 2); dem.resize(n + 2); red.resize(n + 2); for(int i = 0; i < n; i++) { a[i].resize(m + 2); check[i].resize(m + 2); dem[i].resize(m + 2); red[i].resize(m + 2); for(int j = 0; j < m; j++) { cin >> a[i][j]; check[i][j] = dem[i][j] = red[i][j] = false; } } cin >> q; for(int i = 1; i <= q; i++) { cin >> x[i] >> y[i]; if(red[x[i]][y[i]]) { cout << "No"; return 0; } red[x[i]][y[i]] = true; } for(int i = 1; i <= q; i++) { if(!check[x[i]][y[i]]) { tmp = tmp1 = 0; dfs(x[i], y[i]); if(xet.size() < 3 * tmp1) { cout << "No"; return 0; } ans += tmp; sort(xet.begin(), xet.end(), greater<int>()); for(int j = 0; j < 3 * tmp1; j++) ans += xet[j]; xet.clear(); } } cout << ans; return 0; }

Compilation message (stderr)

covering.cpp: In function 'int main()':
covering.cpp:79:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |             if(xet.size() < 3 * tmp1)
      |                ~~~~~~~~~~~^~~~~~~~~~
#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...