이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
#define see(x) cerr<<#x<<"="<<x<<endl;
using namespace std;
const int N = 1002;
int m, n, val[N*N], ans, k, cnt;
bool spec[N*N], used[N*N];
vector <int> g[N*N], values;
void dfs (int v) {
used[v] = true;
if (spec[v]) ++ cnt;
else values.push_back(val[v]);
for (auto i: g[v])
if (!used[i]) dfs(i);
}
int32_t main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> m >> n;
int temp = 1;
for (int i = 0; i < m; ++ i)
for (int j = 0; j < n; ++ j) {
int a; cin >> a;
val[temp ++] = a;
}
cin >> k;
for (int i = 0; i < k; ++ i) {
int x, y;
cin >> x >> y;
++ x; ++ y;
int t = (x-1)*n + y,
t1 = (x-2)*n + y,
t2 = (x-1)*n + y - 1,
t3 = x*n + y,
t4 = (x-1)*n + y + 1;
ans += val[t];
spec[t] = true;
if (x > 1) {
g[t].push_back(t1);
g[t1].push_back(t);
}
if (y > 1) {
g[t].push_back(t2);
g[t2].push_back(t);
}
if (x < m) {
g[t].push_back(t3);
g[t3].push_back(t);
}
if (y < n) {
g[t].push_back(t4);
g[t4].push_back(t);
}
}
temp = 1;
for (int i = 0; i < m; ++ i)
for (int j = 0; j < n; ++ j) {
if (!used[temp]) {
values.clear();
cnt = 0;
dfs(temp);
sort(values.rbegin(), values.rend());
if (3*cnt > values.size()) {
cout << "No\n";
return 0;
}
for (int k = 0; k < 3*cnt; ++ k)
ans += values[k];
}
++ temp;
}
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
covering.cpp: In function 'int32_t main()':
covering.cpp:29:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i < m; ++ i)
^~~
covering.cpp:35:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
cin >> k;
^~~
covering.cpp:74:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (3*cnt > values.size()) {
~~~~~~^~~~~~~~~~~~~~~
# | 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... |