제출 #306830

#제출 시각아이디문제언어결과실행 시간메모리
306830phathnvHandcrafted Gift (IOI20_gift)C++14
100 / 100
212 ms17200 KiB
#include <bits/stdc++.h>
#include "gift.h"

using namespace std;

int construct(int n, int r, vector <int> a, vector <int> b, vector <int> x){
    vector <int> maxR(n, 0), cnt(n, 0);
    for(int i = 0; i < r; i++){
        if (x[i] == 2)
            continue;
        maxR[a[i]] = max(maxR[a[i]], b[i]);
    }
    for(int i = 0; i < n; i++){
        maxR[i] = max(maxR[i], i);
        if (i > 0)
            maxR[i] = max(maxR[i], maxR[i - 1]);
        if (maxR[i] == i){
            cnt[i]++;
        }
        if (i > 0)
            cnt[i] += cnt[i - 1];
    }
    for(int i = 0; i < r; i++){
        if (x[i] == 1)
            continue;
        if (a[i] == b[i])
            return 0;
        int tmp = cnt[b[i] - 1];
        if (a[i] > 0)
            tmp -= cnt[a[i] - 1];
        if (tmp < 1)
            return 0;
    }

    string res;
    res.push_back('B');
    for(int i = 1; i < n; i++)
        res.push_back((cnt[i - 1] & 1)? 'R' : 'B');
    craft(res);
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...