답안 #782614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782614 2023-07-14T06:29:21 Z mychecksedad Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 212 KB
/* 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;
 
}

Compilation message

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;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -