# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
887045 | stefanneagu | Coin Collecting (JOI19_ho_t4) | C++17 | 1 ms | 2396 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |