Submission #887072

# Submission time Handle Problem Language Result Execution time Memory
887072 2023-12-13T15:57:25 Z stefanneagu Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 500 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<=(n<<1); ++i){
      int x, y;
		cin >> x >> y;
		if(x < 1) ans += 1 - x, x = 1;
		else if(x > n) ans += x - n, x = n;
		if(y < 1) ans += 1 - y, y = 1;
		else if(y > 2) ans += y - 2, y = 2;
		++f[x][y];
	}
	*/
  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 <= n; i ++){
    int a = f[i][1] - 1, b = f[i][2] - 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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 500 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 496 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 500 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 496 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 500 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 496 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -