이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |