Submission #779031

# Submission time Handle Problem Language Result Execution time Memory
779031 2023-07-11T06:38:15 Z 이동현(#10002) Bodyguards (CEOI10_bodyguards) C++17
100 / 100
276 ms 22308 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int r, c;
    cin >> r;
    vector<vector<int>> a(r, vector<int>(2));
    for(int i = 0; i < r; ++i){
        cin >> a[i][0] >> a[i][1];
    }
    cin >> c;
    vector<vector<int>> b(c, vector<int>(2));
    for(int i = 0; i < c; ++i){
        cin >> b[i][0] >> b[i][1];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    vector<vector<int>> vc = {{b[0][0] * b[0][1], b[0][1], b[0][1]}};
    int j = 1;
    auto upd = [&](int minus, int cnt){
        while((int)vc.size() > 1){
            int sz = (int)vc.size();
            int s1 = vc[sz - 2][0] - minus * vc[sz - 2][1], s2 = vc[sz - 1][0] - minus * (cnt - vc[sz - 2][2]);
            int v1 = s1 / vc[sz - 2][1];
            if(s1 < 0) v1 -= !!(-s1 % vc[sz - 2][1]);
            int v2 = s2 / vc[sz - 1][1];
            if(s2 < 0) v2 -= !!(-s2 % vc[sz - 1][1]);
            if(v1 > v2){
                break;
            }
            vc[sz - 2][0] += vc[sz - 1][0];
            vc[sz - 2][1] += vc[sz - 1][1];
            vc[sz - 2][2] += vc[sz - 1][1];
            vc.pop_back();
        }
    };
    for(int i = 0; i < r; ++i){
        upd(a[i][1], a[i][0]);
        while(j < c){
            if(vc.back()[2] >= a[i][0]){
                break;
            }
            vc.push_back({b[j][0] * b[j][1], b[j][1], vc.back()[2] + b[j][1]});
            ++j;
            upd(a[i][1], a[i][0]);
        }
        if(vc.back()[2] < a[i][0]){
            cout << "0\n";
            return 0;
        }
        while(j < c){
            int sz = (int)vc.size();
            int psz = (sz >= 2 ? vc[sz - 2][2] : 0);
            int v1 = (vc[sz - 1][0] - a[i][1] * (a[i][0] - psz)) / vc[sz - 1][1];
            // cout << "MJ " << j << ' ' << v1 << ' ' << b[j][0] << endl;
            if(v1 > b[j][0]){
                break;
            }
            vc[sz - 1][0] += b[j][0] * b[j][1];
            vc[sz - 1][1] += b[j][1];
            vc[sz - 1][2] += b[j][1];
            ++j;
            upd(a[i][1], a[i][0]);
        }

        int sz = (int)vc.size();
        for(int k = 0; k < sz - 1; ++k){
            vc[k][0] -= vc[k][1] * a[i][1];
        }
        int psz = (sz >= 2 ? vc[sz - 2][2] : 0);
        vc[sz - 1][0] -= a[i][1] * (a[i][0] - psz);

        for(auto&k:vc){
            if(k[0] < 0){
                cout << "0\n";
                return 0;
            }
        }
        
        // for(auto&k:vc){
        //     cout << k[0] << ' ' << k[1] << ' ' << k[2] << endl;
        // }
        // cout << endl;
    }

    assert(j == c);
    for(auto&k:vc){
        assert(k[0] == 0);
    }
    cout << "1\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 420 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 400 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 852 KB Output is correct
15 Correct 3 ms 852 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 4 ms 852 KB Output is correct
18 Correct 4 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4148 KB Output is correct
2 Correct 17 ms 3096 KB Output is correct
3 Correct 35 ms 4820 KB Output is correct
4 Correct 27 ms 4916 KB Output is correct
5 Correct 27 ms 4948 KB Output is correct
6 Correct 35 ms 5720 KB Output is correct
7 Correct 26 ms 4136 KB Output is correct
8 Correct 37 ms 5716 KB Output is correct
9 Correct 30 ms 5364 KB Output is correct
10 Correct 29 ms 5328 KB Output is correct
11 Correct 29 ms 5328 KB Output is correct
12 Correct 36 ms 5716 KB Output is correct
13 Correct 29 ms 5204 KB Output is correct
14 Correct 29 ms 5756 KB Output is correct
15 Correct 29 ms 5716 KB Output is correct
16 Correct 28 ms 5752 KB Output is correct
17 Correct 29 ms 5792 KB Output is correct
18 Correct 29 ms 5308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 8804 KB Output is correct
2 Correct 51 ms 7408 KB Output is correct
3 Correct 75 ms 10068 KB Output is correct
4 Correct 8 ms 1748 KB Output is correct
5 Correct 76 ms 11272 KB Output is correct
6 Correct 73 ms 8916 KB Output is correct
7 Correct 70 ms 10384 KB Output is correct
8 Correct 8 ms 1620 KB Output is correct
9 Correct 70 ms 11296 KB Output is correct
10 Correct 68 ms 10304 KB Output is correct
11 Correct 60 ms 10304 KB Output is correct
12 Correct 62 ms 10300 KB Output is correct
13 Correct 84 ms 11316 KB Output is correct
14 Correct 71 ms 11188 KB Output is correct
15 Correct 59 ms 11188 KB Output is correct
16 Correct 58 ms 11268 KB Output is correct
17 Correct 59 ms 11220 KB Output is correct
18 Correct 63 ms 11180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 15816 KB Output is correct
2 Correct 97 ms 15628 KB Output is correct
3 Correct 111 ms 13796 KB Output is correct
4 Correct 36 ms 5632 KB Output is correct
5 Correct 112 ms 16900 KB Output is correct
6 Correct 107 ms 22236 KB Output is correct
7 Correct 84 ms 12376 KB Output is correct
8 Correct 118 ms 16340 KB Output is correct
9 Correct 135 ms 20304 KB Output is correct
10 Correct 132 ms 20224 KB Output is correct
11 Correct 165 ms 20280 KB Output is correct
12 Correct 132 ms 20240 KB Output is correct
13 Correct 133 ms 20292 KB Output is correct
14 Correct 11 ms 2260 KB Output is correct
15 Correct 168 ms 22248 KB Output is correct
16 Correct 151 ms 22308 KB Output is correct
17 Correct 276 ms 22284 KB Output is correct
18 Correct 133 ms 20320 KB Output is correct