이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;
ll n, a[N][2], ans = 0;
void solve(){
cin >> n;
deque<pair<ll,ll>> up, down;
for(int i = 0; i < 2*n; ++i){
ll x, y; cin >> x >> y;
if(y >= 2)
up.pb({x, y}), ans += y-2;
else
down.pb({x, y}), ans += abs(1-y);
}
sort(all(up));
sort(all(down));
if(size(up) < size(down)) swap(up, down);
int i = 0;
while(size(up) > size(down)){
if(i%2)
down.pb(up.back()), up.pop_back(), ans++;
else
down.pb(up.front()), up.pop_front(), ans++;
i++;
}
sort(all(up));
sort(all(down));
for(ll i = 0; i < n; ++i){
ans += abs(i + 1 - up[i].first);
ans += abs(i + 1 - down[i].first);
// cout << up[i].first << ' ' << up[i].second << '\n';
// cout << down[i].first << ' ' << down[i].second << '\n';
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:49:14: warning: unused variable 'aa' [-Wunused-variable]
49 | int T = 1, aa;
| ^~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |