Submission #97526

# Submission time Handle Problem Language Result Execution time Memory
97526 2019-02-16T18:41:32 Z dalgerok Coin Collecting (JOI19_ho_t4) C++17
0 / 100
3 ms 512 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e5 + 5;




int n;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int a[3][n + 1];
    memset(a, 0, sizeof(a));
    long long ans = 0;
    for(int i = 1; i <= 2 * n; i++){
        int x, y;
        cin >> x >> y;
        if(y < 1){
            ans += 1 - y;
            y = 1;
        }
        else if(y > 2){
            ans += y - 2;
            y = 2;
        }
        if(x < 1){
            ans += 1 - x;
            x = 1;
        }
        else if(x > n){
            ans += x - n;
            x = n;
        }
        a[y][x] += 1;
    }
    vector < int > q[3], s[3];
    for(int i = 1; i <= n; i++){
        q[1].push_back(i);
        q[2].push_back(i);
        for(int j = 1; j <= 2; j++){
            for(int k = 1; k <= a[j][i]; k++){
                s[j].push_back(i);
            }
        }
        for(int j = 1; j <= 2; j++){
            while(!q[j].empty() && !s[j].empty()){
                ans += abs(q[j].back() - s[j].back());
                q[j].pop_back();
                s[j].pop_back();
            }
        }
        for(int j = 1; j <= 2; j++){
            while(!q[j].empty() && !s[3 - j].empty()){
                ans += abs(q[j].back() - s[3 - j].back()) + 1;
                q[j].pop_back();
                s[j].pop_back();
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -