이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pi pair<int, int>
#define fr(i, m, n) for (int i = m; i <= n; i++)
#define frr(i, m, n) for (int i = m; i >= n; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define endl '\n'
#define el cout << endl
#define inf 1e18
#define mii map<int, int>
#define pb push_back
#define sz size()
#define pi pair<int, int>
#define vpi vector<pi>
#define si set<int>
int n, m, a, b, c, d, e, x, y, z, w, i, j, qq, k, l, r;
int mi = inf, ma, cnt, ans;
bool id;
string s;
const int N = 1e6 + 5;
vi dx = {0, 0, 1, -1, 1, 1, -1, -1, 0, 0, 2, -2};
vi dy = {1, -1, 0, 0, -1, 1, -1, 1, 2, -2, 0, 0};
vector<array<int, 3>> an;
int vis[N];
map<pi, int>mp;
pi v[N];
void solve() {
cin >> n >> m;
int g[n + 1][m + 1];
fr(i, 1, n) {
fr(j, 1, m) {
cin >> g[i][j];
}
}
cin >> k;
fr(i, 1, k) {
cin >> a >> b; v[i] = {a, b}; mp[ {a, b}] = i;
}
fr(i, 1, k) {
if (vis[i]) continue;
auto [a, b] = v[i];
int siz = 0;
queue<array<int, 3>>q; q.push({a, b, i});
set<pi> isi;
vector<pi> aw;
while (q.sz) {
auto[a, b, tc] = q.front(); q.pop();
// cout << a << " " << b << " " << tc; el;
aw.pb({a, b}); siz++;
// isi.insert({a, b});
ans += g[a][b];
vis[tc] = 1;
fr(i, 0, 11) {
x = a + dx[i];
y = b + dy[i];
z = mp[ {x, y}];
if (x >= 1 and x <= n and y >= 1 and y <= m and z and !vis[z]) {
q.push({x, y, mp[{x, y}]});
}
}
}
// cout << isi.sz; el;
for (auto [a, b] : aw) {
fr(i, 0, 3) {
x = a + dx[i];
y = b + dy[i];
if (x >= 1 and x <= n and y >= 1 and y <= m) {
if (mp[ {x, y}]) continue;
isi.insert({x, y});
}
}
// cout << a << " " << b; el;
}
priority_queue<int>pq;
for (auto [a, b] : isi) pq.push(-g[a][b]), ans += g[a][b];
// cout << ans << " ";
while (pq.sz > 3 * siz) {
auto k = pq.top(); pq.pop();
ans -= -k;
}
}
cout << "TEPAT"; el;
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) {
cout << fixed << setprecision(12); solve();
el;
} return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
covering.cpp: In function 'void solve()':
covering.cpp:87:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
87 | while (pq.sz > 3 * siz) {
| ~~~~~~^~~~~~~~~
# | 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... |