QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214811#6552. Good and Lucky Matricesucup-team180#0 173ms66948kbC++173.2kb2023-10-15 00:11:422023-10-15 00:11:43

Judging History

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

  • [2023-10-15 00:11:43]
  • 评测
  • 测评结果:0
  • 用时:173ms
  • 内存:66948kb
  • [2023-10-15 00:11:42]
  • 提交

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);
  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 = N - 1; j >= 0; j--){
      if (B[i][j]){
        used[j] = true;
        break;
      }
    }
  }
  vector<vector<int>> ans(N, vector<int>(N));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      ans[i][j] = B[i][j];
    }
  }
  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: 3664kb

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: 3888kb

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: 173ms
memory: 66948kb

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: 164ms
memory: 66780kb

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)