# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369385 | AriaH | Coin Collecting (JOI19_ho_t4) | C++11 | 62 ms | 5996 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.
/** Im the best because i work as hard as i possibly can **/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Mp make_pair
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl "\n"
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }
ll tot;
ll n, A[N][3], cnt[3];
int main()
{
scanf("%lld", &n);
for(int i = 1; i <= n << 1; i ++)
{
ll x, y; scanf("%lld%lld", &x, &y);
if(x < 1)
{
tot += 1 - x;
x = 1;
}
if(x > n)
{
tot += x - n;
x = n;
}
if(y < 1)
{
tot += 1 - y;
y = 1;
}
if(y > 2)
{
tot += y - 2;
y = 2;
}
A[x][y] ++;
}
for(int i = 1; i <= n; i ++)
{
cnt[1] += A[i][1] - 1;
cnt[2] += A[i][2] - 1;
if(cnt[1] < 0 && cnt[2] > 0)
{
ll cu = min(-cnt[1], cnt[2]);
tot += cu;
cnt[1] += cu;
cnt[2] -= cu;
}
else if(cnt[2] < 0 && cnt[1] > 0)
{
ll cu = min(-cnt[2], cnt[1]);
tot += cu;
cnt[2] += cu;
cnt[1] -= cu;
}
tot += abs(cnt[1]);
tot += abs(cnt[2]);
}
printf("%lld\n", tot);
return 0;
}
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... |