# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
422958 | schse | Handcrafted Gift (IOI20_gift) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void craft(string s)
{
cout<<s;
}
struct requirement
{
int l, r, x;
bool operator<(requirement a) const
{
return x == a.x ? l < a.l : x < a.x;
}
};
int construct(int n, int r, int *a, int *b, int *x)
{
std::vector<requirement> rec;
rec.resize(r);
bool allsame = true;
bool alldiff = true;
for (int i = 0; i < r; i++)
{
rec[i].l = a[i];
rec[i].r = b[i];
rec[i].x = x[i];
if (x[i] == 2)
allsame = false;
else
alldiff = false;
}
string str;
str.resize(n);
if (allsame)
{
fill(str.begin(), str.end(), 'R');
craft(str);
return 1;
}
if (alldiff)
{
for (int i = 0; i < n; i++)
str[i] = i % 2 ? 'B' : 'R';
craft(str);
return 1;
}
fill(str.begin(), str.end(), '0');
sort(rec.begin(), rec.end());
queue<requirement> scol, mcol;
for (auto i : rec)
{
if (i.x == 1)
scol.push(i);
else
mcol.push(i);
}
for (int col=0, i = 0; i < n; i++)
{
if(str[i]=='0')
{
col++,col%=2;
str[i]=col?'R':'B';
}
if(!scol.empty() && scol.front().l==i)
{
fill(&str[scol.front().l],&str[scol.front().r+1],str[scol.front().l]);
scol.pop();
}
}
while (!mcol.empty())
{
bool r=false,b=false;
for (int i = mcol.front().l; i < mcol.front().r+1; i++){
if(str[i]=='R')
r=true;
else
b=true;
}
if(!r||!b)
return 0;
mcol.pop();
}
craft(str);
return 1;
}
int main()
{
int n = 4, r = 2,
a[2] = {0, 2};
int b[2] = {2, 3};
int x[2] = {2, 1};
construct(n, r, a, b, x);
}