| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1332831 | retarde | Coin Collecting (JOI19_ho_t4) | C++20 | 38 ms | 3580 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
int cnt[400005][4];
inline void solve() {
int n; cin >> n; 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;}
cnt[x][y]++;
}
int cnta = 0, cntb = 0;
for (int i = 1; i <= n; i++) {
cnt[i][1]--; cnt[i][2]--;
cnta += cnt[i][1]; cntb += cnt[i][2];
if (cnta < 0 && cntb > 0) {
int amt = min(cntb, -cnta);
ans += amt;
cntb -= amt;
cnta += amt;
} else if (cnta > 0 && cntb < 0) {
int amt = min(-cntb, cnta);
ans += amt;
cntb += amt;
cnta -= amt;
}
ans += abs(cnta + cntb);
}
cout << ans << '\n';
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
