This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Problem: B - Coin Collecting
// Contest: Virtual Judge - Yosik IOI contest #1
// URL: https://vjudge.net/contest/601761#problem/B
// Memory Limit: 268 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) (v).begin(),(v).end()
#define rall(v) ((v).rbegin()), ((v).rend())
#define out(v) for(auto& i : v) cout << i << ' ';
#define F first
#define S second
#define int long long
const ll N = 1e5 + 17;
const ll MOD = 1e9 + 7;
const string alf = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n;
int dp[N][4];
pair <int , int > xy[] = {{0 , 1} , {0 , -1} , {1 , 0} , {-1 , 0}};
bool oke(int x ,int y){
if (n >= 1 && n <= n && y >= 1 && y <= 2)return true;
return false;
}
void solve (){
cin >> n;
map <pair <int , int > ,int > cnt;
int ans = 0;
queue <pair <int , int > > q;
for(int i = 1; i <= 2 * n; i ++){
int x , y;
cin >> x >> y;
int cur = 0 , cur2 = 0;
if (x >= 1 && x <= n){}
else {
if (abs(x - 1) <= abs(x - n)){
ans += abs(x - 1);
x = 1;
}
else {
ans += abs(x - n);
x = n;
}
}
if (y >= 1 && y <= 2){}
else {
if (abs(y - 1) <= abs(y - 2)){
ans += abs(y - 1);
y = 1;
}
else {
ans += abs(y - 2);
y = 2;
}
}
dp[x][y] ++;
}
// cout << ans << endl;
int cur = 0 , cur2 = 0;
for(int i = 1; i <= n; i ++){
cur += dp[i][1] - 1;
cur2 += dp[i][2] - 1;
// cout << cur << " " << cur2 << endl;
while (cur > 0 && cur2 < 0){
ans ++;
cur --;
cur2 ++;
}
while (cur < 0 && cur2 > 0){
ans ++;
cur ++;
cur2 --;
}
ans += abs(cur + cur2);
}
cout << ans;
cout << endl;
}
signed main(){
// freopen("ones.in" , "r" , stdin) ;
// freopen("ones.out" , "w" , stdout) ;
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
// int cs = 1;
// cin >>T;
while (T --){
// cout <<"Case " << cs ++<< ":" << endl;
solve ();
// cout <<endl;
}
}
Compilation message (stderr)
joi2019_ho_t4.cpp: In function 'bool oke(long long int, long long int)':
joi2019_ho_t4.cpp:30:18: warning: self-comparison always evaluates to true [-Wtautological-compare]
30 | if (n >= 1 && n <= n && y >= 1 && y <= 2)return true;
| ~ ^~ ~
joi2019_ho_t4.cpp: In function 'void solve()':
joi2019_ho_t4.cpp:42:7: warning: unused variable 'cur' [-Wunused-variable]
42 | int cur = 0 , cur2 = 0;
| ^~~
joi2019_ho_t4.cpp:42:17: warning: unused variable 'cur2' [-Wunused-variable]
42 | int cur = 0 , cur2 = 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... |