| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 904876 | KK_1729 | Handcrafted Gift (IOI20_gift) | C++17 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "gift.h"
#define int long long 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}
bool compare(pair<int, int> x, pair<int, int> y){
    if (x.first < y.first) return true;
    if (x.first == y.first){
        if (x.second < y.second) return true;
    }
    return false;
}
bool intersect(pair<int, int> x, pair<int, int> y){
    if (y.first < x.first) swap(x, y);
    if (x.second >= y.first) return true;
    return false;
}
int construct(int n, int r, vector<int> a, vector<int> b, vector<int> x) {
    vector<int> ans(n);
    vector<int> component(n);
    
    vector<pair<int, int>> first;
    vector<pair<int, int>> second;
    FOR(i,0,r){
        int l = a[i]; int r = b[i]; int t = x[i];
        if (t == 1){
            first.pb({l, r});
        }else{
            second.pb({l, r});
        }
    }
    FOR(i,0,n) first.pb({i, i});
    sort(all(first));
    vector<pair<int, int>> ranges;
    pair<int, int> current = {0, 0};
    FOR(i,0,first.size()){
        if (i == 0){
            current = first[i];
            continue;
        }
        if (intersect(first[i], current)){
            current.second = max(current.second, first[i].second);
        }else{
            ranges.pb(current);
            current = first[i];
        }
    }
    ranges.pb(current);
    int comp = 0;
    // cout << endl;
    for (auto x: ranges){
        
        FOR(i,x.first,x.second+1){
            component[i] = comp;
            if (comp%2){
                ans[i] = 0;
            }else{
                ans[i] = 1;
            }
        }
        comp++;
    }
    for (auto x: second){
        if (component[x.first] == component[x.second]){
            return 0;
        }
    }
	string answer = "";
    for (auto x: ans){
        if (x) answer+='R';
        else answer+='B';
    }
	// cout << answer << endl;
    craft(answer);
	return 1;
}
