제출 #1158722

#제출 시각아이디문제언어결과실행 시간메모리
1158722vladiliusWorst Reporter 2 (JOI16_worst_reporter2)C++20
0 / 100
14 ms320 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n; cin>>n;
    vector<int> a(n + 1), c(n + 1), f[n + 1];
    for (int i = 1; i <= n; i++){
        cin>>a[i]>>c[i];
        f[a[i]].pb(c[i]);
    }
    for (int i = 1; i <= n; i++){
        reverse(f[i].begin(), f[i].end());
    }
    vector<int> b(n + 1), d(n + 1);
    for (int i = 1; i <= n; i++){
        cin>>b[i]>>d[i];
    }
    
    vector<int> s(n + 1);
    int out = n;
    for (int i = n; i > 0; i--){
        int x = b[i];
        if (s[x] != f[x].size() && f[x][s[x]] <= d[i]){
            out--;
            s[x]++;
        }
    }
    
    
    int out1 = n, tt = 1;
    vector<int> p = {0};
    for (int i = 1; i <= n; i++){
        tt *= i;
        p.pb(i);
    }
    while (tt--){
        bool I = 0;
        for (int i = 1; i <= n; i++){
            if (d[p[i]] < c[i]){
                I = 1;
                break;
            }
        }
        if (!I){
            int cc = 0;
            for (int i = 1; i <= n; i++){
                cc += (a[i] != b[p[i]]);
            }
            out1 = min(out1, cc);
        }
        next_permutation(p.begin() + 1, p.end());
    }
    
    assert(out == out1);
    cout<<out<<"\n";
    // cout<<out<<" "<<out1<<"\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...