이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
#define lb(s, a) lower_bound(all(s), (a)) - s.begin()
#define ii pair <int, int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int ar = 2e5+5;
const ll mod = 1e9+7;
const int oo = 1e9;
int n, m, k;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "d"
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> m >> n;
vector <vector <int>> a(m + 1, vector <int> (n + 1, 0));
vector <vector <bool>> ok(m + 1, vector <bool> (n + 1, 0));
vector <vector <bool>> vs(m + 1, vector <bool> (n + 1, 0));
for(int i = 1; i <= m; ++i)
for(int j = 1; j <= n; ++j)
cin >> a[i][j];
cin >> k;
int x, y;
for(int i = 1; i <= k; ++i) {
cin >> x >> y;
x++;
y++;
ok[x][y] = 1;
}
int res = 0;
for(int i = 1; i <= m; ++i)
for(int j = 1; j <= n; ++j) if(!vs[i][j] && ok[i][j]) {
vs[i][j] = 1;
queue <ii> q;
q.push({i, j});
vector <int> val;
int cnt = 0;
while(q.size()) {
int u = q.front().fi, v = q.front().se;
q.pop();
if(ok[u][v]) {
cnt++, res += a[u][v];
// cout << u << ' ' << v << '\n';
}
else val.push_back(a[u][v]);
for(int t = 0; t < 4; ++t) {
int x = u + dx[t], y = v + dy[t];
if(x > 0 && y > 0 && x <= m && y <= n && !vs[x][y] && (ok[u][v] || ok[x][y]))
vs[x][y] = 1, q.push({x, y});
}
}
if(val.size() < 3 * cnt) cout << "No", exit(0);
// cout << i << ' ' << j << '\n';
int del = 1;
if(val.size() == 3 * cnt) del = 0;
int nn = *min_element(all(val));
for(auto x : val) {
if(del && x == nn) {
del = 0;
continue;
}
// cout << x << ' ';
res += x;
}
// cout << '\n';
}
cout << res;
}
컴파일 시 표준 에러 (stderr) 메시지
covering.cpp: In function 'int main()':
covering.cpp:69:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
69 | if(val.size() < 3 * cnt) cout << "No", exit(0);
| ~~~~~~~~~~~^~~~~~~~~
covering.cpp:73:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
73 | if(val.size() == 3 * cnt) del = 0;
| ~~~~~~~~~~~^~~~~~~~~~
covering.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
covering.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |