QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214854 | #6552. Good and Lucky Matrices | ucup-team180# | 0 | 179ms | 66864kb | C++17 | 3.3kb | 2023-10-15 00:32:53 | 2023-10-15 00:32:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> encode_good(int N, vector<vector<int>> A){
vector<bitset<2000>> B(N);
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
if (A[i][j]){
B[i].set(j);
}
}
}
vector<bool> used(N, false);
vector<vector<int>> ans(N);
vector<int> top(N);
for (int i = 0; i < N; i++){
for (int j = 0; j < i; j++){
ans[i].push_back(B[i][top[j]]);
if (B[i][top[j]]){
B[i] ^= B[j];
}
}
for (int j = 0; j < N; j++){
if (!used[j]){
ans[i].push_back(B[i][j]);
}
}
for (int j = N - 1; j >= 0; j--){
if (B[i][j]){
top[i] = j;
break;
}
}
used[top[i]] = true;
}
return ans;
}
vector<vector<int>> decode_good(int N, vector<vector<int>> A){
vector<bitset<2000>> B(N);
vector<bool> used(N, false);
vector<vector<int>> ans(N, vector<int>(N));
for (int i = 0; i < N; i++){
for (int j = 0; j < i; j++){
if (A[i][j]){
B[i] ^= B[j];
}
}
int cnt = 0;
for (int j = 0; j < N; j++){
if (!used[j]){
if (A[i][i + cnt]){
B[i][j] = !B[i][j];
}
cnt++;
}
}
for (int j = 0; j < N; j++){
ans[i][j] = B[i][j];
}
for (int j = 0; j < i; j++){
if (A[i][j]){
B[i] ^= B[j];
}
}
for (int j = N - 1; j >= 0; j--){
if (B[i][j]){
used[j] = true;
break;
}
}
}
return ans;
}
vector<vector<int>> encode_lucky(int N, vector<vector<int>> A){
vector<bool> used(N, false);
vector<vector<int>> ans(N);
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
if (used[j]){
ans[i].push_back(A[i][j]);
}
}
for (int j = 0; j < N; j++){
if (!used[j]){
ans[i].push_back(A[i][j]);
}
}
for (int j = 0; j < N; j++){
if (!used[j] && A[i][j]){
used[j] = true;
break;
}
}
}
return ans;
}
vector<vector<int>> decode_lucky(int N, vector<vector<int>> A){
vector<bool> used(N, false);
vector<vector<int>> ans(N, vector<int>(N, 0));
for (int i = 0; i < N; i++){
int p = 0;
for (int j = 0; j < N; j++){
if (used[j]){
ans[i][j] = A[i][p];
p++;
}
}
for (int j = 0; j < N; j++){
if (!used[j]){
ans[i][j] = A[i][p];
p++;
}
}
for (int j = 0; j < N; j++){
if (!used[j] && A[i][j]){
used[j] = true;
break;
}
}
}
return ans;
}
int main(){
int t;
cin >> t;
for (int i = 0; i < t; i++){
string s;
cin >> s;
int n;
cin >> n;
vector<vector<int>> A(n, vector<int>(n));
for (int j = 0; j < n; j++){
string S;
cin >> S;
for (int k = 0; k < n; k++){
A[j][k] = S[k] - '0';
}
}
vector<vector<int>> ans;
if (s == "good"){
ans = decode_lucky(n, encode_good(n, A));
}
if (s == "lucky"){
ans = decode_good(n, encode_lucky(n, A));
}
cout << n << endl;
for (int j = 0; j < n; j++){
for (int k = 0; k < n; k++){
cout << ans[j][k];
}
cout << endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
First Run Input
3 lucky 2 11 11 good 2 11 01 lucky 2 01 10
First Run Output
2 11 01 2 11 11 2 01 10
Second Run Input
3 good 2 11 01 lucky 2 11 11 good 2 01 10
Second Run Output
2 11 11 2 11 01 2 01 10
result:
ok 9 lines
Test #2:
score: 100
Accepted
time: 0ms
memory: 3792kb
First Run Input
3 good 2 11 10 lucky 2 11 01 good 2 01 10
First Run Output
2 11 01 2 11 10 2 01 10
Second Run Input
3 lucky 2 11 01 good 2 11 10 lucky 2 01 10
Second Run Output
2 11 10 2 11 01 2 01 10
result:
ok 9 lines
Test #3:
score: 100
Accepted
time: 172ms
memory: 66724kb
First Run Input
1 good 2000 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
First Run Output
2000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Input
1 lucky 2000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Output
2000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok 2001 lines
Test #4:
score: 100
Accepted
time: 179ms
memory: 66864kb
First Run Input
1 lucky 2000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
First Run Output
2000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Input
1 good 2000 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Output
2000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok 2001 lines
Test #5:
score: 0
Wrong Answer on the first run
First Run Input
1 good 2000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
First Run Output
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Input
Second Run Output
result:
wrong answer Matrix should be lucky (test case 1)