QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127866 | #6644. Red Black Grid | xjsc01 | WA | 1ms | 3528kb | C++23 | 2.0kb | 2023-07-20 10:44:44 | 2023-07-20 10:44:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
inline int cal(int u, int v){
int ans = 0;
for(int k = 0; k < 4; k++){
int x = u+dx[k];
int y = v+dy[k];
if(x < 1 || x > n || y < 1 || y > n) continue;
ans ++;
}
return ans;
}
void solve(int &cnt2, int &cnt3, int &cnt4, int n, int m){
cnt2 = cnt3 = cnt4 = 0;
int tot4 = 0, tot2 = 0, tot3 = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if((i+j)&1) continue;
int ret = cal(i, j);
if(ret == 2) tot2++;
else if(ret == 3) tot3++;
else if(ret == 4) tot4++;
}
}
int sub = 2*n*(n-1) - m;
if(sub & 1)
tot3--, cnt3++, sub--;
{
int can = tot3/2;
int di_num = min(can, sub/6);
cnt3 += di_num * 2;
tot3 -= di_num * 2;
sub -= di_num * 6;
}
if(!sub) return ;
{
int can = tot4;
int di_num = min(can, sub/4);
cnt4 += di_num;
tot4 -= di_num;
sub -= di_num * 4;
}
if(!sub) return ;
{
int can = tot2;
int di_num = min(can, sub/2);
cnt2 += di_num;
tot2 -= di_num;
sub -= di_num * 2;
}
}
int main()
{
int T;
cin >> T;
while(T--){
scanf("%d%d", &n, &m);
int tot = 2*n*(n-1);
if(n == 1) puts("Impossible");
else if(m == 1 || m == tot - 1){
puts("Impossible");
}
else if(m > tot) {
puts("Impossible");
}
else {
puts("Possible");
int cnt2, cnt3, cnt4;
solve(cnt2, cnt3, cnt4, n, m);
cout << "cnt:" << cnt2 << " "<<cnt3<<" "<<cnt4<<endl;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if((i+j)&1){
putchar('B');
}
else{
int ret = cal(i, j);
if(ret == 2){
if(cnt2) putchar('B'), cnt2--;
else putchar('R');
}
else if(ret == 3){
if(cnt3) putchar('B'), cnt3--;
else putchar('R');
}
else{
if(cnt4) putchar('B'), cnt4--;
else putchar('R');
}
}
}
puts("");
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3528kb
input:
2 3 6 3 1
output:
Possible cnt:1 0 1 BBR BBB RBR Impossible
result:
wrong answer Condition failed: "A.length() == n" (test case 1)