QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#796542 | #6380. LaLa and Divination Magic | rookiefyq# | WA | 1ms | 7968kb | C++14 | 2.5kb | 2024-12-01 20:44:02 | 2024-12-01 20:44:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2333;
bitset<N> bt[N], at[N];
int n, m, ok[N * 2], vis[N * 2];
string st;
vector<int> e[N * 2];
bitset<N * 2> d[N * 2], nd[N * 2];
bool flag;
void bfs(int u){
memset(vis, 0, sizeof vis);
queue<int> q;
q.push(u);
vis[u] = 1;
while(!q.empty()){
int v = q.front();
q.pop();
d[u].set(v);
for(auto v1 : e[v]){
if(!vis[v1]){
q.push(v1);
vis[v1] = 1;
}
}
}
}
void dfs(bitset<N * 2> now, int k){
if(!flag) return ;
if(k == m){
n--;
if(n < 0){
flag = 0;
}
return ;
}
if(now[k] | now[k + m]) {
return dfs(now, k + 1);
}
bitset<N * 2> b1, b2;
b1 = now & nd[k];
b2 = now & nd[k + m];
if(b1.count() == 0)
dfs(now | d[k], k + 1);
if(b2.count() == 0)
dfs(now | d[k + m], k + 1);
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> st;
for(int j = 0; j < m; j++){
if(st[j] == '1') bt[j].set(i);
else at[j].set(i);
}
}
bitset<N> b[5];
flag = 1;
vector<array<int, 3>> ans;
for(int i = 0; i < m; i++){
if(bt[i].count() == n) ans.push_back({i, i, 4}), ok[i] = 1;
else if(at[i].count() == n) ans.push_back({i, i, 1}), ok[i + m] = 1;
for(int j = i + 1; j < m; j++){
b[1] = at[i] | at[j];
b[4] = bt[i] | bt[j];
b[2] = bt[i] | at[j];
b[3] = at[i] | bt[j];
bool f = 0;
for(int t = 1; t < 5; t++){
if(b[t].count() == n){
f = 1;
ans.push_back({i, j, t});
if(t == 1){
e[i].push_back(j + m);
e[j].push_back(i + m);
}
else if(t == 2){
e[i + m].push_back(j + m);
e[j].push_back(i);
}
else if(t == 3){
e[i].push_back(j);
e[j + m].push_back(i + m);
}
else {
e[i + m].push_back(j);
e[j + m].push_back(i);
}
}
}
if(!f){
flag = 0;
break;
}
}
}
if(!flag) cout <<"-2\n";
else {
for(int i = 0; i < m * 2; i++){
bfs(i);
for(int j = 0; j < m * 2; j++)
if(d[i][j]) nd[i][(j + m) % (2 * m)] = 1;
}
bitset<N * 2> now;
for(int i = 0; i < m * 2; i++)
if(ok[i]) now |= d[i];
dfs(now, 0);
if(!flag){
cout << "-2\n";
return ;
}
cout << ans.size() << '\n';
assert(ans.size() <= 2 * m * m);
for(auto[i, j, t] : ans){
cout << i << " " << j << " " << t << '\n';
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7888kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #2:
score: 0
Accepted
time: 0ms
memory: 7740kb
input:
3 3 101 011 111
output:
6 0 1 4 0 2 3 0 2 4 1 2 3 1 2 4 2 2 4
result:
ok Kout = 6, Kans = 6
Test #3:
score: 0
Accepted
time: 0ms
memory: 7656kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #4:
score: 0
Accepted
time: 1ms
memory: 7664kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #5:
score: 0
Accepted
time: 1ms
memory: 7704kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 7664kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #7:
score: 0
Accepted
time: 0ms
memory: 7920kb
input:
2 1 0 1
output:
0
result:
ok Kout = 0, Kans = 0
Test #8:
score: 0
Accepted
time: 0ms
memory: 5788kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #9:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
1 1 1
output:
1 0 0 4
result:
ok Kout = 1, Kans = 1
Test #10:
score: 0
Accepted
time: 0ms
memory: 7660kb
input:
1 1 0
output:
1 0 0 1
result:
ok Kout = 1, Kans = 1
Test #11:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #12:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #13:
score: 0
Accepted
time: 1ms
memory: 7968kb
input:
2 4 0111 0010
output:
15 0 0 1 0 1 1 0 1 3 0 2 1 0 2 3 0 2 4 0 3 1 0 3 3 1 2 3 1 2 4 1 3 2 1 3 3 2 2 4 2 3 2 2 3 4
result:
ok Kout = 15, Kans = 15
Test #14:
score: 0
Accepted
time: 0ms
memory: 7800kb
input:
2 1 1 0
output:
0
result:
ok Kout = 0, Kans = 0
Test #15:
score: -100
Wrong Answer
time: 1ms
memory: 5652kb
input:
4 2 10 11 01 00
output:
-2
result:
wrong answer Integer parameter [name=K] equals to -2, violates the range [-1, 8]