QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214903 | #6552. Good and Lucky Matrices | ucup-team133# | 0 | 130ms | 4792kb | C++20 | 3.8kb | 2023-10-15 01:12:58 | 2023-10-15 01:12:59 |
Judging History
answer
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <bitset>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i+=1)
#define append push_back
#define all(x) (x).begin(), (x).end()
template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<class T>
bool chmin(T &a, T b){
if (a>b){
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b){
if (a<b){
a = b;
return true;
}
return false;
}
template<class T>
T sum(vec<T> x){
T res=0;
for (auto e:x){
res += e;
}
return res;
}
template<class T>
void printv(vec<T> x){
for (auto e:x){
cout<<e<<" ";
}
cout<<"\n";
}
template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
os << "{";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ", ";
}
}
os << "}" ;
return os;
}
template<class T>
ostream& operator<<(ostream& os, const deque<T>& A){
os << "deque{[";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ", ";
}
}
os << "]}" ;
return os;
}
template<class T>
ostream& operator<<(ostream& os, const pair<T,T>& A){
os << "(";
os << A.first ;
os << ", ";
os << A.second;
os << ")";
return os;
}
const int M = 2000;
vec<bitset<M>> lucky_to_good(int N,vec<bitset<M>> A){
vec<int> r_to_c(N,-1);
vec<int> c_to_r(N,-1);
rep(i,N){
rep(j,N){
if (c_to_r[j] != -1) continue;
if (A[i][j]){
r_to_c[i] = j;
c_to_r[j] = i;
break;
}
}
}
vec<bitset<M>> good_det(N);
rep(i,N){
int top_bit = r_to_c[i];
assert (top_bit!=-1);
good_det[i][top_bit] = 1;
for (int j=top_bit+1;j<N;j++){
good_det[i][j] = A[i][j];
}
rep(j,top_bit){
if (c_to_r[j] < i && A[i][j]){
good_det[i] ^= good_det[c_to_r[j]];
}
}
}
return good_det;
}
vec<bitset<M>> good_to_lucky(int N,vec<bitset<M>> A){
vec<int> top_bit_to_r(N,-1);
vec<int> r_to_top_bit(N,-1);
vec<bitset<M>> lucky_det(N);
rep(i,N){
rep(top_bit,N){
if (top_bit_to_r[top_bit] == -1) continue;
int t = int(A[i]._Find_first());
if (t < top_bit) break;
if (t == top_bit){
A[i] ^= A[top_bit_to_r[top_bit]];
lucky_det[i][top_bit] = 1;
}
}
int top_bit = int(A[i]._Find_first());
top_bit_to_r[top_bit] = i;
r_to_top_bit[i] = top_bit;
for (int j=top_bit;j<N;j++){
lucky_det[i][j] = A[i][j];
}
}
return lucky_det;
}
void solve(){
string S;
cin>>S;
int N;
cin>>N;
vec<bitset<M>> A(N);
rep(i,N){
string row;
cin>>row;
rep(j,N){
if (row[j] == '1'){
A[i][j] = 1;
}
}
}
if (S == "lucky"){
auto res = lucky_to_good(N,A);
cout << N << endl;
rep(i,N){
rep(j,N){
cout << res[i][j];
}
cout << endl;
}
}
else{
auto res = good_to_lucky(N,A);
cout << N << endl;
rep(i,N){
rep(j,N){
cout << res[i][j];
}
cout << endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin>>T;
while (T--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
First Run Input
3 lucky 2 11 11 good 2 11 01 lucky 2 01 10
First Run Output
2 11 10 2 11 01 2 01 10
Second Run Input
3 good 2 11 10 lucky 2 11 01 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: 3832kb
First Run Input
3 good 2 11 10 lucky 2 11 01 good 2 01 10
First Run Output
2 11 11 2 11 01 2 01 10
Second Run Input
3 lucky 2 11 11 good 2 11 01 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: 109ms
memory: 4684kb
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: 122ms
memory: 4792kb
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: 100
Accepted
time: 113ms
memory: 4748kb
First Run Input
1 good 2000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
First Run Output
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Input
1 lucky 2000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Output
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok 2001 lines
Test #6:
score: 100
Accepted
time: 102ms
memory: 4652kb
First Run Input
1 lucky 2000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
First Run Output
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Input
1 good 2000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
Second Run Output
2000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok 2001 lines
Test #7:
score: 0
Wrong Answer
time: 130ms
memory: 4728kb
First Run Input
1 lucky 2000 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
First Run Output
2000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
Second Run Input
1 good 2000 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
Second Run Output
2000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
wrong answer 4th lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: '011111111111111111111111111111...1111111111111111111111111111111'