Submission #904876

# Submission time Handle Problem Language Result Execution time Memory
904876 2024-01-12T10:41:23 Z KK_1729 Handcrafted Gift (IOI20_gift) C++17
Compilation error
0 ms 0 KB
#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;
}





Compilation message

gift.cpp: In function 'long long int construct(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
gift.cpp:7:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
gift.cpp:50:5: note: in expansion of macro 'FOR'
   50 |     FOR(i,0,first.size()){
      |     ^~~
/usr/bin/ld: /tmp/ccSRuEjD.o: in function `main':
grader.cpp:(.text.startup+0x272): undefined reference to `construct(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status