Submission #497060

# Submission time Handle Problem Language Result Execution time Memory
497060 2021-12-22T09:15:06 Z kingline Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 324 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
//#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >

using namespace std;

typedef long long ll;
const int N = 1e6 + 5;
const int M = 350;
const int mod = 1e9 + 7;

int n, x[N], y[N], cnt[N][5];

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //file("pieaters");
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= (n << 1); i++) {
        cin >> x[i] >> y[i];
        if(x[i] > n) {
            ans += x[i] - n;
            x[i] = n;
        }
        if(x[i] < 1) {
            ans += 1 - x[i];
            x[i] = 1;
        }
        if(y[i] > 2) {
            ans += y[i] - 2;
            y[i] = 2;
        }
        if(y[i] < 1) {
            ans += 1 - y[i];
            y[i] = 1;
        }
        cnt[x[i]][y[i]]++;
    }
    int a = 0, b = 0;
    for(int i = 1; i <= n; i++) {
        a += cnt[i][1] - 1;
        b += cnt[i][2] - 1;
        int sv = min(abs(a), abs(b));
        if(a < 0 && b > 0) {
            a += sv;
            b -= sv;
            ans += sv;
        } else if(a > 0 && b < 0) {
            a -= sv;
            b += sv;
            ans += sv;
        }
        ans += abs(a);
        ans += abs(b);
    }
    cout << ans;
}

/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/









Compilation message

joi2019_ho_t4.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Incorrect 0 ms 324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Incorrect 0 ms 324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Incorrect 0 ms 324 KB Output isn't correct
3 Halted 0 ms 0 KB -