Submission #896509

# Submission time Handle Problem Language Result Execution time Memory
896509 2024-01-01T15:07:08 Z Andrey Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,a,b,ans = 0,br1 = 0,br2 = 0;
    cin >> n;
    vector<long long> haha(n);
    for(long long i = 0; i < 2*n; i++) {
        cin >> a >> b;
        if(a > n) {
            ans+=a-n;
            a = n;
        }
        else if(a < 1) {
            ans+=1-a;
            a = 1;
        }
        if(b < 1) {
            ans+=1-b;
            b = 1;
        }
        else if(b > 2) {
            ans+=b-2;
            b = 2;
        }
        haha[a-1]++;
        if(b == 1) {
            br1++;
        }
        else {
            br2++;
        }
    }
    ans+=abs(br1-br2)/2;
    stack<pair<long long,long long>> idk;
    for(long long i = 0; i < n; i++) {
        if(haha[i] < 2) {
            while(!idk.empty() && haha[i] < 2 && idk.top().second == 1) {
                ans+=i-idk.top().first;
                idk.pop();
                haha[i]++;
            }
            while(haha[i] < 2) {
                haha[i]++;
                idk.push({i,0});
            }
        }
        else if(haha[i] > 2) {
            while(!idk.empty() && haha[i] > 2 && idk.top().second == 0) {
                ans+=i-idk.top().first;
                idk.pop();
                haha[i]--;
            }
            while(haha[i] > 2) {
                haha[i]--;
                idk.push({i,1});
            }
        }
    }
    if(idk.size() > 0) {
        cout << 1/0;
    }
    cout << ans;
    return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:65:18: warning: division by zero [-Wdiv-by-zero]
   65 |         cout << 1/0;
      |                 ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -