# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28663 | 욱제한테백구주나 (#68) | Oriental P.A.D.A.K (FXCUP2_padak) | C++11 | 1000 ms | 57868 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 <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
int N, M, K, B, Z;
unordered_map<ll, int> dist;
bool inRange(int i, int j){
return 0 <= i && i < N && 0 <= j && j < M;
}
int cnt[1000003];
int backup[1000003];
int main() {
fastio();
cin >> N >> M >> K >> B >> Z;
queue<pair<int,int> > q;
for(int i = 0 ; i < K; i++){
int r,c;
cin >> r >> c;
r--, c--;
q.push({r, c});
dist[1000000 * r + c] = 0;
}
int maxD = 0;
while(!q.empty()){
auto p = q.front();
q.pop();
int ci = p.first;
int cj = p.second;
for(int k = 0 ; k < 4; k++){
int ni = ci + "1021"[k] - '1';
int nj = cj + "0112"[k] - '1';
if(!inRange(ni, nj) || dist.find(1000000 * ni + nj) != dist.end()) continue;
int d = dist[1000000 * ni + nj] = dist[1000000 * ci + cj] + 1;
cnt[d]++;
maxD = max(maxD, d);
q.push({ni, nj});
}
}
for(int i = 0; i <= maxD; i++) backup[i] = cnt[i];
int ans1 = 0;
int t = 0;
int cur = Z;
for(int i = maxD; t < i;) {
if(cnt[i] > cur){
cnt[i] -= cur;
ans1 += cur;
cur = Z;
t++;
}
else {
cur -= cnt[i];
ans1 += cnt[i];
i--;
}
}
cout << ans1 << endl;
for(int i = 0 ; i <= maxD; i++) cnt[i] = backup[i];
int ans2 = 0;
t = 0;
int pos = 1;
cur = Z;
while(t < maxD && pos <= maxD) {
if(t == pos) pos = t + 1;
if(cnt[pos] > cur){
cnt[pos] -= cur;
ans2 += cur;
cur = Z;
t++;
}
else {
cur -= cnt[pos];
ans2 += cnt[pos];
pos++;
}
}
cout << ans2;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |