답안 #747462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747462 2023-05-24T08:04:36 Z vjudge1 Kralj (COCI16_kralj) C++17
56 / 140
2000 ms 46468 KB
#include "bits/stdc++.h"
#define ll long long
using namespace std;
const ll mod = 1000000007;

vector<int> v[500001];
vector<int> vec;
multiset<int> s;
int ans;
int ind, sz;

void solve() {
    for(int i = ind; i < sz; i++) {
        auto it = s.upper_bound(vec[i]);
        if(it != s.end()) {
            ans++;
            s.erase(it);
        }
        else
            s.erase(s.begin());
    }
    ind = sz;
}
const int N = 1e6 + 5;
    int a[N], b[N], c[N], be[N], en[N];

signed main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        be[a[i] - 1]++;
    }
    int x = 0;
    for(int i = 0; i < n; i++) {
        if(be[i]) {
            en[(i + be[i] - 1) % n]++;
            if(i + be[i] - 1 >= n)
                x++;
        }
    }
    int st = 0;
    for(int i = 0; i < n; i++) {
        x += (be[i] > 0);
        if(be[i] && x == 1)
            st = i;
        x -= en[i];
    }
    for(int i = 0; i < n; i++)
        cin >> b[i];
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        v[a[i] - 1].push_back(c[i]);
    }
    for(int i = 0; i <= n; i++) {
        if(be[st] || i == n)
            solve();
        for(int j : v[st])
            s.insert(j);
        vec.push_back(b[st]);
        st++;
        sz++;
        st %= n;
    }
    cout << ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1160 ms 40252 KB Output is correct
2 Correct 984 ms 39664 KB Output is correct
3 Correct 1248 ms 45652 KB Output is correct
4 Correct 1157 ms 46468 KB Output is correct
5 Execution timed out 2082 ms 24196 KB Time limit exceeded
6 Execution timed out 2054 ms 24860 KB Time limit exceeded
7 Execution timed out 2081 ms 27756 KB Time limit exceeded
8 Execution timed out 2059 ms 27608 KB Time limit exceeded
9 Execution timed out 2019 ms 29108 KB Time limit exceeded
10 Execution timed out 2058 ms 26792 KB Time limit exceeded