| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1364046 | dex111222333444555 | Coin Collecting (JOI19_ho_t4) | C++20 | 24 ms | 1608 KiB |
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define ii pair<int, int>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define dbg(x) "[" #x " = " << x << "]"
using namespace std;
const long long inf = 1e18 + 132;
const int infINT = 1e9 + 132;
template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
const int MAXN = 1e5 + 5;
const ii d[4] = {{+1, +1}, {+1, -1}, {-1, +1}, {-1, -1}};
int numVal, cnt[MAXN][3];
void input(){
cin >> numVal;
}
void solve(){
long long res = 0;
for(int i = 1; i <= 2 * numVal; i++){
int x, y; cin >> x >> y;
int sx = x, sy = y;
if (x < 1) x = 1;
else if (x > numVal) x = numVal;
if (y <= 1) y = 1;
else y = 2;
cnt[x][y]++;
res += abs(sx - x) + abs(sy - y);
}
int d1 = 0, d2 = 0;
for(int x = 1; x <= numVal; x++){
d1 += (cnt[x][1] - 1);
d2 += (cnt[x][2] - 1);
if (d1 < 0 && d2 > 0){
int t = min(-d1, d2);
d1 += t; d2 -= t;
res += t;
}
if (d1 > 0 && d2 < 0){
int t = min(d1, -d2);
d1 -= t; d2 += t;
res += t;
}
res += abs(d1) + abs(d2);
}
cout << res << '\n';
cerr << res << '\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int t = 1;
// cin >> t;
while(t--){
input();
solve();
}
cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
