답안 #887068

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

const int nmax = 3e5 + 1;

int f[nmax][3];

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 << " ";
    // punem in cel mai apropiat loc
    if(a < 1) {
      //cout << "b mai mic ";
      ans += 1 - a;
      a = 1;
    } else if(a > n) {
      //cout << "b mai mare ";
      ans += a - n;
      a = n;
    }
    if(b < 1) {
      //cout << "a mai mic ";
      ans += 1 - b;
      b = 1;
    } else if(b > 2) {
      //cout << "a mai mare ";
      ans += b - 2;
      b = 2;
    }
    //cout << endl;
    f[a][b] ++;
  }
  /*
  for(int i = 1; i <= 2; i ++) {
    for(int j = 1;  j <= n; j ++) {
      cout << f[i][j] << " ";
    }
    cout << endl;
  }
  */
  for(int i = 1; i <= n; i ++) {
    for(int j = 1; j <= 2; j ++) {
      if(f[i][j] == 0) {
        int minn = 1e9, ni, nj;
        for(int x = 1; x <= n; x ++) {
          for(int y = 1; y <= 2; y ++) {
            if(f[x][y] > 1 && minn > abs(x - i) + abs(y - j)) {
              ni = x;
              nj = y;
              minn = abs(x - i) + abs(y - j);
            }
          }
        }
        f[i][j] ++;
        f[ni][nj] --;
        ans += minn;
      }
    }
  }
  cout << ans;
  return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int32_t main()':
joi2019_ho_t4.cpp:63:19: warning: 'nj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |         f[ni][nj] --;
      |         ~~~~~~~~~~^~
joi2019_ho_t4.cpp:63:19: warning: 'ni' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 460 KB Output isn't correct
7 Halted 0 ms 0 KB -