답안 #887059

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887059 2023-12-13T15:11:24 Z stefanneagu Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 2548 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int nmax = 1e5 + 1;

int f[3][nmax];

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, ans = 0;
  cin >> n;
  for(int i = 1; i <= 2 * n; i ++) {
    int a, b;
    cin >> a >> b;
    //cout << i << " ";
    swap(a, b);
    // punem in cel mai apropiat loc
    if(a < 1 && b < 1) { // daca ii in stanga sus
        //cout << "ss: " << 1 - a + 1 - b << endl;
      ans += 1 - a + 1 - b;
      f[1][1] ++;
    } else if(a < 1 && b > n) { // daca ii in dreapta sus
      ans += 1 - a + b - n;
      f[1][n] ++;
    //cout << "ds: "<< 1 - a + b - n << endl;
    } else if(a > 2 && b < 1) { // daca ii in stanga jos
      ans += a - 2 + 1 - b;
      f[2][1] ++;
      //cout << "sj: "<< a - 2 + 1 - b << endl;
    } else if(a > 2 && b > n) { // daca ii in dreapta jos
      ans += a - 2 + b - n;
      f[2][n] ++;
      //cout << "dj: "<< a - 2 + b - n << endl;
    } else if(a < 1) { // daca ii sus
      ans += 1 - a;
      f[1][b] ++;
      //cout << "sus: "<< 1 - a  << endl;
    } else if(a > 2) { // daca ii jos
      ans += a - 2;
      f[2][b] ++;
      //cout << "jos: "<< a - 2 << endl;
    } else if(b > n) { // daca ii dreapta
      ans += b - n;
      f[a][n] ++;
      //cout << "dreapta: "<< b - n << endl;
    } else if(b < 1) { // daca ii stanga
      ans += 1 - b;
      f[a][1] ++;
      //cout << "stanga: "<< 1 - b << endl;
    } else { // e inauntru
      f[a][b] ++;
      //cout << "inauntru: "<< 0 << endl;
    }
  }
  for(int i = 1; i <= n; i ++){
    int a = f[1][i] - 1, b = f[2][i] - 1;
    while(a > 0 && b < 0) {
      a --;
      b ++;
      ans ++;
    }
    while(a < 0 && b > 0) {
      a ++;
      b --;
      ans ++;
    }
    ans += abs(a) + abs(b);
	}
  cout << ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2548 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -