Submission #1063910

# Submission time Handle Problem Language Result Execution time Memory
1063910 2024-08-18T06:01:32 Z _8_8_ Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
    
using namespace std;
    
typedef long long ll;
const int  N = 1e6 + 12, MOD = (int)1e9 + 7;
#define int ll
int n;
int c[N][3],a[N];
int dist(int x,int y,int x1,int y1) {
    return abs(x - x1) + abs(y - y1);
}
ll ans = 0;
void test() {
    cin >> n;
    for(int i = 1;i <= n + n;i++) {
        int a,b;
        cin >> a >> b;
        int x = 1,y = 1;
        auto upd = [&](int x1,int y1) {
            if(dist(x1,y1,a,b) < dist(x,y,a,b)) {
                x = x1;
                y = y1;
            }
        };
        upd(1,2);
        upd(n,1);
        upd(n,2);
        if(a >= 1 && a <= n) {
            upd(a,1);
            upd(a,2);
        }
        if(b >= 1 && b <= 2) {
            upd(1,b);
            upd(n,b);
        }
        c[x][y]++;
        ans += dist(x,y,a,b);
    }
    int x  =0,y = 0;
    for(int i = 1;i <= n;i++) {
        x += c[i][1];
        y += c[i][2];
        a[i] = c[i][1] + c[i][2];
    }
    // for(int i = 1;i <= n;i++) {
    //     cout << c[i][1] << ' ' << c[i][2] << '\n';
    // }
    ans += abs(x - y) / 2;
    vector<int> l,r;
    for(int i = 1;i <= n;i++) {
        for(int j = 0;j < a[i] - 2;j++) {
            l.push_back(i);
        }
        for(int j = 0;j < 2 - a[i];j++) {
            r.push_back(i);
        }
    }
    assert((int)l.size() == (int)r.size());
    for(int i = 0;i < (int)l.size();i++) {
        ans += abs(l[i] - r[i]);
    }
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}  
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 344 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 0 ms 348 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 344 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 0 ms 348 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 344 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 -