Petrozavodsk Winter Camp, Day 8, 2014, Mosaic

时间:2021-08-07 07:58:19

给你三个数字a,b,c,让你用1~m的数字凑出来

结论:有2个1和2个2肯定凑不出来,然后就搜索

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = int(j); i <= int(k); ++ i)
#define dwn(i, j, k) for (int i = int(j); i >= int(k); -- i)
typedef long long LL;
typedef pair<int, int> P;
const int N = 3e5 + ;
char col[N];
int dfs(int i, int j, int k, int x) {
if (i == && j == && k == ) return ;
if (i < || j < || k < || x <= ) return ;
col[x] = ;
if (dfs(i - x, j, k, x - )) return ;
col[x] = ;
if (dfs(i, j - x, k, x - )) return ;
col[x] = ;
if (dfs(i, j, k - x, x - )) return ;
return ;
}
int main() {
ios::sync_with_stdio();
LL a, b, c;
cin >> a >> b >> c;
LL n = a + b + c;
LL x = ;
for (x = ; n > ; x ++) n -= x; x --; int xx = x;
int c1 = (a == ) + (b == ) + (c == );
int c2 = (a == ) + (b == ) + (c == );
if (c1 >= || c2 >= || n != ) {
printf("Impossible\n");
return ;
}
dfs(a, b, c, x);
// cout << a << ' ' << b << ' ' << c << ' ' << x << '\n';
auto tran = [&](int x) -> char {
if (x == ) return 'W';
if (x == ) return 'G';
return 'B';
};
rep(i, , xx) printf("%c", tran(col[i]));
}
/*
11 5 5
*/