# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28573 | 일단아무거나적어놓은팀이름 (#68) | Oriental P.A.D.A.K (FXCUP2_padak) | C++14 | 623 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int n, m, k, b, z, c1[1000010], c2[1000010];
int dir[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
vector<vector<int> > T;
bool is_valid(int x, int y) {
return x >= 1 && y >= 1 && x <= m && y <= n;
}
int main() {
scanf("%d%d%d%d%d", &n, &m, &k, &b, &z);
T = vector<vector<int> >(n + 1, vector<int>(m + 1, -1));
queue<pair<int, int> > q;
for(int i = 0, r, c; i < k; ++i) {
scanf("%d%d", &r, &c);
T[r][c] = 0;
q.push({c, r});
}
while(!q.empty()) {
int x = q.front().first;
int y = q.front().second; q.pop();
for(int i = 0; i < 4; ++i) {
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if(!is_valid(tx, ty) || T[ty][tx] >= 0) continue;
T[ty][tx] = T[y][x] + 1;
q.push({tx, ty});
}
}
int mx = 0;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j)
c1[T[i][j]]++, c2[T[i][j]]++, mx = max(mx, T[i][j]);
int r1 = 0, r2 = 0;
for(int t = 1, last = 1; ; ++t) {
if(last > mx) break;
int rem = z;
while(rem > 0) {
if(last > mx) break;
int eat = min(c1[last], rem);
c1[last] -= eat;
rem -= eat;
r1 += eat;
if(!c1[last]) last++;
}
if(last == t) last++;
}
for(int t = 1, last = mx; ; ++t) {
int rem = z;
while(rem > 0) {
if(t > last) break;
int eat = min(c2[last], rem);
c2[last] -= eat;
rem -= eat;
r2 += eat;
if(!c2[last]) last--;
}
if(t > last) break;
}
printf("%d %d", r2, r1);
return 0;
}
/*
3 4 3 2 3
1 1
2 4
3 2
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |