QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796478#6380. LaLa and Divination Magicrookiefyq#WA 1ms7992kbC++142.4kb2024-12-01 19:41:362024-12-01 19:41:37

Judging History

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

  • [2024-12-01 19:41:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7992kb
  • [2024-12-01 19:41:36]
  • 提交

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 <<"-1\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 << "-1\n";
			return ;
		}	
		cout << ans.size() << '\n';
		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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #2:

score: 0
Accepted
time: 1ms
memory: 7948kb

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: 1ms
memory: 7688kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #4:

score: 0
Accepted
time: 1ms
memory: 7980kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #5:

score: 0
Accepted
time: 0ms
memory: 7944kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #6:

score: 0
Accepted
time: 0ms
memory: 7676kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #7:

score: 0
Accepted
time: 1ms
memory: 7740kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #8:

score: 0
Accepted
time: 1ms
memory: 7688kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #9:

score: 0
Accepted
time: 0ms
memory: 7980kb

input:

1 1
1

output:

1
0 0 4

result:

ok Kout = 1, Kans = 1

Test #10:

score: 0
Accepted
time: 0ms
memory: 5724kb

input:

1 1
0

output:

1
0 0 1

result:

ok Kout = 1, Kans = 1

Test #11:

score: 0
Accepted
time: 1ms
memory: 7992kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #12:

score: 0
Accepted
time: 1ms
memory: 5840kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #13:

score: 0
Accepted
time: 1ms
memory: 6008kb

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: 1ms
memory: 7636kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #15:

score: -100
Wrong Answer
time: 1ms
memory: 5672kb

input:

4 2
10
11
01
00

output:

-1

result:

wrong answer Jury has a solution while the participant doesn't, Kans = 0