Submission #887045

# Submission time Handle Problem Language Result Execution time Memory
887045 2023-12-13T14:22:50 Z stefanneagu Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 2396 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 <= 2; i ++) {
    for(int j = 1; j <= n; j ++) {
      if(f[i][j] == 0) {
        int minn = 1e9, ni, nj;
        for(int x = 1; x <= 2; x ++) {
          for(int y = 1; y <= n; 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:72:19: warning: 'nj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |         f[ni][nj] --;
      |         ~~~~~~~~~~^~
joi2019_ho_t4.cpp:72:19: warning: 'ni' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Halted 0 ms 0 KB -