QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#174408#6644. Red Black GridUNos_maricones#WA 49ms3464kbC++173.3kb2023-09-10 07:14:492023-09-10 07:14:49

Judging History

你现在查看的是最新测评结果

  • [2023-09-10 07:14:49]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:3464kb
  • [2023-09-10 07:14:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ff   first
#define ss   second
#define pb   push_back

typedef long long   ll;
typedef pair<int,int>   ii;

const int N = 3e5+5;
const int mod = 1e9+7;


int v[1005][1005];

int main() { 
	#ifdef LOCAL
	freopen("in.txt","r",stdin);
	#endif
		
		
	int t; cin >> t;
	while (t--) { 
		int n; cin >> n;
		int k; cin >> k;
		if (k == 1) { 
			cout << "Impossible\n";
			continue;
		}
		if (n == 4 && k == 7) {
			cout << "Possible\n"; 
			for (int i = 0; i < n; ++i) { 
				for (int j = 0; j < n; ++j) { 
					if ((i == 1 && j == 1) || (i == 3 && j == 2)) cout << "B";
					else cout << "R";
				}
				cout << '\n';
			}
			continue;
		}
		if (n <= 3) { 
			for (int i = 0; i < (1<<(n*n)); ++i) { 
				for (int j = 0; j < n; ++j) { 
					for (int k = 0; k < n; ++k) { 
						int pos = j * n + k;
						if (i & (1<<pos)) v[j][k] = 1;
						else v[j][k] = 0;
					}
				}
				int cnt = 0;
				for (int j = 0; j < n; ++j) { 
					for (int k = 0; k < n; ++k) { 
						if (j + 1 < n && abs(v[j + 1][k] - v[j][k]) == 1) cnt++;
						if (k + 1 < n && abs(v[j][k + 1] - v[j][k]) == 1) cnt++; 
					}
				}
				if (cnt == k) { 
					cout << "Possible\n";
					for (int j = 0; j < n; ++j)  {
						for (int k = 0; k < n; ++k) { 
							if (v[j][k]) cout << "B";
							else cout << "R";
						}
						cout << '\n';
					}
					break;
				}
				if (i + 1 == (1<<(n*n))) {
					cout << "Impossible\n";
				}
			}
			continue;
		}
		if ((n == 4 && k <= 6) || (n > 4 && k <= 8)) { 
			for (int i = 0; i < n; ++i) 
				for (int j = 0; j < n; ++j) v[i][j] = 0;
			
			cout << "Possible\n";
			if (k > 0) {
				v[0][0] = 1;
				k -= 2;
				for (int i = 1; i + 1 < n && k; ++i, --k) v[0][i] = 1;
				for (int j = 1; j + 1 < n && k; ++j, --k) v[j][0] = 1;
			}
			for (int j = 0; j < n; ++j)  {
				for (int k = 0; k < n; ++k) { 
					if (v[j][k]) cout << "B";
					else cout << "R";
				}
				cout << '\n';
			}			  
			continue;
		}
		
		vector <ii> two, three, four;
		for (int i = 0 ; i < n; ++i) { 
			for (int j = 0; j < n; ++j) { 
				if ((i + j) % 2 == 0) { 
					v[i][j] = 1;
					if ((i == 0 && j == 0) || (i == 0 && j == n-1) || (i == n-1 && j == 0) || (i == n-1 && j == n-1)) two.pb({i,j});
					else if (i == 0 || j == 0 || i == n-1 || j == n-1) three.pb({i,j});
					else four.pb({i, j});
				}
				else v[i][j] = 0;
				
			}
		}
		
		int rst = 2 * n * (n-1) - k;
		if (rst == 1) { 
			cout << "Impossible\n";
			continue;
		}
		
		int idx3=0,idx4=0;
		
		while (rst >= 1) { 
			if (rst >= 4 && idx4 < four.size()) { 
				v[four[idx4].ff][four[idx4].ss] ^= 1;
				idx4++;
				rst-=4;
			}
			else if (rst >= 3 && idx3 < three.size()) { 
				v[three[idx3].ff][three[idx3].ss] ^= 1;
				idx3++;
				rst-=3;
			}
			else {
				if (rst == 2) { 
					v[two[0].ff][two[0].ss] ^= 1;
					rst -= 2;
				}
				else if (rst == 1) { 
					v[four.back().ff][four.back().ss] ^= 1;
					v[three[0].ff][three[0].ss] ^= 1;
					v[two[0].ff][two[0].ss] ^= 1;
					rst--;
				}
			}
		}
		
		cout << "Possible\n";
		for (int j = 0; j < n; ++j)  {
			for (int k = 0; k < n; ++k) { 
				if (v[j][k]) cout << "B";
				else cout << "R";
			}
			cout << '\n';
		}
	}
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3436kb

input:

2
3 6
3 1

output:

Possible
RBR
BRR
RRR
Impossible

result:

ok correct! (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 49ms
memory: 3464kb

input:

4424
1 0
2 4
2 3
2 2
2 1
2 0
3 12
3 11
3 10
3 9
3 8
3 7
3 6
3 5
3 4
3 3
3 2
3 1
3 0
4 24
4 23
4 22
4 21
4 20
4 19
4 18
4 17
4 16
4 15
4 14
4 13
4 12
4 11
4 10
4 9
4 8
4 7
4 6
4 5
4 4
4 3
4 2
4 1
4 0
5 40
5 39
5 38
5 37
5 36
5 35
5 34
5 33
5 32
5 31
5 30
5 29
5 28
5 27
5 26
5 25
5 24
5 23
5 22
5 21
5...

output:

Possible
R
Possible
RB
BR
Impossible
Possible
BR
RR
Impossible
Possible
RR
RR
Possible
RBR
BRB
RBR
Impossible
Possible
BRB
RBR
BRR
Possible
RBR
BRB
RRR
Possible
BRB
RBR
RRR
Possible
RRB
BBR
RRR
Possible
RBR
BRR
RRR
Possible
RRB
BRR
RRR
Possible
BRB
RRR
RRR
Possible
RBR
RRR
RRR
Possible
BRR
RRR
RRR
I...

result:

wrong answer Condition failed: "getNum(vec) == k" (test case 25)