| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1347548 | ChottuF | Coin Collecting (JOI19_ho_t4) | C++20 | 0 ms | 344 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
vector<vector<int>> dp(2, vector<int>(n,-1));
int ans = 0;
for (int i = 0; i<2*n; i++){
int x,y;
cin >> x >> y;
if (x <= 1){
ans += 1-x;
x = 1;
}
if (x >= n){
ans += x-n;
x = n;
}
if (y <= 1){
ans += 1-y;
y = 1;
}
if (y >= 2){
ans += y-2;
y = 2;
}
x--;y--; //0-index lol
dp[y][x]++;
}
for (int i = 0; i<n; i++){
int one = dp[0][i];
int two = dp[1][i];
if (one >= 0 && two <= 0){
int df = min(abs(one), abs(two));
dp[0][i] -= df;
dp[1][i] += df;
ans += df;
}
else if (one <= 0 && two >= 0){
int df = min(abs(one), abs(two));
dp[0][i] += df;
dp[1][i] -= df;
ans += df;
}
if (i+1 < n){
dp[0][i+1] += dp[0][i];
dp[1][i+1] += dp[1][i];
ans += abs(one) + abs(two);
}
}
cout << ans;
return 0;
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
