답안 #256904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256904 2020-08-03T11:21:17 Z Osama_Alkhodairy Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, a[2][N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll ans = 0;
    for(int i = 0 ; i < 2 * n ; i++){
        int x, y;
        cin >> x >> y;
        int nx = min(n, max(1, x));
        int ny = min(2, max(1, y));
        ans += abs(nx - x) + abs(ny - y);
        a[ny - 1][nx - 1]++;
    }
    int sum = a[0][0] + a[1][0];
    for(int j = 1 ; j < n ; j++){
        int g = max(sum - 2 * j, 0);
        int x = min(g, max(0, a[0][j - 1] - 1));
        sum += a[0][j] + a[1][j];
        a[0][j - 1] -= x;
        a[0][j] += x;
        g -= x;
        ans += x;
        x = min(g, max(0, a[1][j - 1] - 1));
        a[1][j - 1] -= x;
        a[1][j] += x;
        g -= x;
        ans += x;
    }
    sum = a[0][n - 1] + a[1][n - 1];
    for(int j = n - 2 ; j >= 0 ; j--){
        int g = max(sum - 2 * (n - j - 1), 0);
        int x = min(g, max(0, a[0][j + 1] - 1));
        sum += a[0][j] + a[1][j];
        a[0][j + 1] -= x;
        a[0][j] += x;
        g -= x;
        ans += x;
        x = min(g, max(0, a[1][j + 1] + 1));
        a[1][j + 1] -= x;
        a[1][j] += x;
        g -= x;
        ans += x;
    }
    for(int j = 0 ; j < n ; j++){
        if(a[0][j] != 1) ans++;
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -