답안 #778979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
778979 2023-07-11T06:04:29 Z 이동현(#10002) Bodyguards (CEOI10_bodyguards) C++17
0 / 100
109 ms 16444 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 v1 = (vc[sz - 2][0] - minus * vc[sz - 2][1]) / vc[sz - 2][1];
            int v2 = (vc[sz - 1][0] - minus * (cnt - vc[sz - 2][2])) / 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]);
        }
        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];
            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]);
        }
        // for(auto&k:vc){
        //     cout << k[0] << ' ' << k[1] << ' ' << k[2] << endl;
        // }

        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;
            }
        }
    }

    cout << "1\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 232 KB Output is correct
10 Incorrect 0 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 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 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 212 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 384 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 384 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 320 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 852 KB Output is correct
2 Incorrect 3 ms 676 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4592 KB Output is correct
2 Incorrect 17 ms 3660 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 9064 KB Output is correct
2 Incorrect 58 ms 8316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 16236 KB Output is correct
2 Correct 108 ms 16444 KB Output is correct
3 Incorrect 106 ms 14620 KB Output isn't correct
4 Halted 0 ms 0 KB -