제출 #163050

#제출 시각아이디문제언어결과실행 시간메모리
163050_qVp_Kralj (COCI16_kralj)C++14
140 / 140
919 ms53164 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair < int, int > II;
const int md = 5e5 + 10;

int n;
int a[md], b[md], pre[md];
vector < int > adj[md];

int solve(int start) {
    int res = 0;
    set < int > S;
    for(int i = start, j = 1; j <= n; j++, i = i % n + 1) {
        for(int j = 0; j < adj[i].size(); j++)
            S.insert(adj[i][j]);
        set < int > :: iterator it = S.upper_bound(b[i]);
        if (it == S.end()) 
            S.erase(S.begin());
        else {
            S.erase(it);
            res++;
        }
    }
    return res;
}

int main() {
    //freopen("test.in", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pre[i] = -1;
    }
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    II start = II(1e9, 1e9);
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        adj[a[i]].push_back(x); 
        //cout << a[i] << " " << x << endl;
        pre[a[i]]++;
    }
    for(int i = 1; i <= n; i++) {
        pre[i] += pre[i - 1];
        start = min(start, II(pre[i], i));
    }
    cout << solve(start.second % n + 1);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

kralj.cpp: In function 'int solve(int)':
kralj.cpp:16:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < adj[i].size(); j++)
                        ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...