QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#122610 | #6644. Red Black Grid | installb# | RE | 0ms | 0kb | C++14 | 2.7kb | 2023-07-10 20:15:36 | 2023-07-10 20:15:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[2005][2005];
int n,k;
void solve(){
vector <pair <int,pair <int,int> > > G;
cin >> n >> k;
// special judge for N=3
if(n == 3){
if(k == 3){
cout << "Possible\n";
cout << "BRB\n";
cout << "BBB\n";
cout << "BBB\n";
return;
}
if(k == 5){
cout << "Possible\n";
cout << "BRB\n";
cout << "BBB\n";
cout << "BBR\n";
return;
}
if(k == 7){
cout << "Possible\n";
cout << "BRB\n";
cout << "BBB\n";
cout << "RBR\n";
return;
}
if(k == 9){
cout << "Possible\n";
cout << "BRB\n";
cout << "RBR\n";
cout << "BBB\n";
return;
}
}
for(int i = 1;i <= n;i ++){
for(int j = (i & 1) ? 1 : 2;j <= n;j += 2){
if(i == 1 || j == 1 || i == n || j == n){
if((i == 1 && j == 1) || (i == n && j == n) || (i == 1 && j == n) || (i == n && j == 1)) G.push_back({2,{i,j}});
else G.push_back({3,{i,j}});
}
else G.push_back({4,{i,j}});
}
}
sort(G.begin(),G.end());
reverse(G.begin(),G.end());
if(k > n * (n - 1)){
k = n * (n - 1) * 2 - k;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
a[i][j] = 1;
}
}
for(int i = 1;i <= n;i ++){
for(int j = (i & 1) ? 1 : 2;j <= n;j += 2){
a[i][j] = 0;
}
}
}
else{
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
a[i][j] = 0;
}
}
}
for(auto [v,p] : G){
auto [x,y] = p;
if(k - v == 1 || k - v < 0) continue;
k -= v; a[x][y] = 1;
}
if(k != 0){
cout << "Impossible\n";
assert(0);
return;
}
cout << "Possible\n";
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
cout << (a[i][j] ? 'R' : 'B');
}
cout << '\n';
}
}
int main(){
ios::sync_with_stdio(false);
int TC;
cin >> TC;
while(TC --){
solve();
}
// for(int i = 3;i <= 50;i ++){
// for(int j = 0;j <= 2 * i * (i - 1);j ++){
// if(j == 1 || j + 1 == 2 * i * (i - 1)) continue;
// n = i; k = j;
// cout << n << ',' << k << endl; solve();
// }
// }
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
2 3 6 3 1
output:
Possible BBB BRB BBR