# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497073 | vinnipuh01 | Coin Collecting (JOI19_ho_t4) | C++17 | 177 ms | 6100 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 <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int bl[ 1000001 ][ 3 ];
queue <pair<int, int> > q, qq;
int d( int x, int y, int xx, int yy ) {
return abs( x - xx ) + abs( y - yy );
}
main () {
int n;
cin >> n;
pair<int, int> a[ n + n + 1 ];
int y, x;
int x1, y1, x2, y2, x3, y3, x4, y4;
x1 = y1 = 1;
x2 = 1, y2 = 2;
x3 = n, y3 = 1;
x4 = n, y4 = 2;
for ( int i = 1; i <= n + n; i ++ ) {
cin >> a[ i ].first >> a[ i ].second;
if ( a[ i ].second <= 1 ) {
y = 1;
if ( a[ i ].first >= 1 && a[ i ].first <= n )
x = a[ i ].first;
else {
if ( a[ i ].first < 1 )
x = 1;
else
x = n;
}
}
else {
y = 2;
if ( a[ i ].first >= 1 && a[ i ].first <= n )
x = a[ i ].first;
else {
if ( a[ i ].first < 1 )
x = 1;
else
x = n;
}
}
ans += d( x, y, a[ i ].first, a[ i ].second );
bl[ x ][ y ] ++;
}
mn = 0;
for ( int i = 1; i <= n; i ++ ) {
bl[ i ][ 1 ] --;
if ( bl[ i ][ 1 ] > 0 ) {
sum += bl[ i ][ 1 ];
}
else if ( bl[ i ][ 1 ] < 0 ) {
mx ++;
}
bl[ i ][ 2 ] --;
if ( bl[ i ][ 2 ] > 0 )
num += bl[ i ][ 2 ];
else if ( bl[ i ][ 2] < 0 )
mn ++;
if ( mn && num ) {
if ( mn < num ) {
num -= mn;
mn = 0;
}
else
mn -= num, num = 0;
}
if ( mx && sum ) {
if ( mx < sum )
sum -= mx, mx = 0;
else
mx -= sum, sum = 0;
}
if ( mn && sum ) {
ans += min( mn, sum );
if ( mn < sum )
sum -= mn, mn = 0;
else
mn -= sum, sum = 0;
}
if ( mx && num ) {
ans += min( mx, num );
if ( mx < num )
num -= mx, mx = 0;
else
mx -= num, num = 0;
}
ans += num + sum + mx + mn;
}
cout << ans;
}
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... |