QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127928 | #6644. Red Black Grid | xjsc01 | RE | 0ms | 0kb | C++23 | 3.1kb | 2023-07-20 11:50:40 | 2023-07-20 11:50:41 |
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};
int tepan = 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;
}
char ran[3000][3000];
void judged(int std){
// for(int i = 1; i <= n; i++)
// for(int j = 1; j <= n; j++)
// putchar(ran[i][j]);
int ans = 0;
for(int u = 1; u <= n; u++){
for(int v = 1; v <= n; v++){
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;
if(ran[u][v] == 'R' && ran[x][y] == 'B') ans++;
}
}
}
//cout << ans<< endl;
assert(std == 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 == tepan) 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-=3;
{
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 && m >= 1) puts("Impossible");
else if(m == 1 || m == tot - 1){
puts("Impossible");
}
else if(m > tot) {
puts("Impossible");
}
else if(n == 3){//如果直接使用上面的就是要么拥有2,4的,要么拥有3的
puts("Possible");
if(m==2)puts("RBB\nBBB\nBBB");
if(m==3)puts("BRB\nBBB\nBBB");
if(m==4)puts("RBR\nBBB\nBBB");
if(m==5)puts("RRB\nBBB\nBBR");
if(m==6)puts("RBR\nBBB\nRBB");
if(m==7)puts("BRB\nBRB\nBBB");
if(m==8)puts("RBR\nBBB\nRBR");
if(m==9)puts("BRB\nRBR\nBBB");
if(m==10)puts("RBR\nBRB\nRBB");
if(m==12)puts("RBR\nBRB\nRBR");
judged(m);
}
else {
tepan = 1;
puts("Possible");
int cnt2, cnt3, cnt4;
solve(cnt2, cnt3, cnt4, n, m);
// cout << "tot" << tot<<" \n";
// cout << "cnt:" << cnt2 << " "<<cnt3<<" "<<cnt4<<endl;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if((i+j)&1 == tepan){
putchar('B');
ran[i][j] = 'B';
}
else{
int ret = cal(i, j);
if(ret == 2){
if(cnt2) putchar('B'),ran[i][j] = 'B', cnt2--;
else putchar('R'),ran[i][j] = 'R';
}
else if(ret == 3){
if(cnt3) putchar('B'),ran[i][j] = 'B', cnt3--;
else putchar('R'),ran[i][j] = 'R';
}
else{
if(cnt4) putchar('B'),ran[i][j] = 'B', cnt4--;
else putchar('R'),ran[i][j] = 'R';
}
}
}
puts("");
}
judged(m);
}
}
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