QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101573#6380. LaLa and Divination Magiczhoukangyang#WA 2ms3672kbC++171.7kb2023-04-30 12:28:542023-04-30 12:28:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-30 12:28:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3672kb
  • [2023-04-30 12:28:54]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long 
#define bs bitset < N >
using namespace std;
const int N = 4007, M = 2007;
const double pi = acos(-1);
int n, m;
string s[N]; 
bitset < N > F[N][2], e[N], all;
bitset < N > odd;
int cont = 0;
inline void dfs(int x, bitset < N > cur) {
	if((((cur & odd) << 1) & cur).any()) 
		return ;
	if(x == m) {
		++cont;
		if(cont > n) {
			cout << "-1\n";
			exit(0);
		} 
		return ;
	}
	if(!cur[x * 2 + 1]) {
		dfs(x + 1, cur | e[x * 2]);
	} 
	if(!cur[x * 2]) {
		dfs(x + 1, cur | e[x * 2 + 1]);
	}
}
int fb[N][N][2][2];
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	L(i, 1, n) {
		cin >> s[i];
		L(j, 0, m - 1) {
			F[j][s[i][j] - '0'].set(i); 
		} 
	}
	L(i, 1, n)
		all.set(i);
	int cons = 0;
	L(x, 0, m - 1) {
		L(y, x, m - 1) {
			L(a, 0, 1) {
				L(b, 0, 1) {
					if((F[x][a] | F[y][b]) == all) {
						++cons;
						fb[x][y][a][b] = 1;
						e[x * 2 + (a ^ 1)].set(y * 2 + b);
						e[y * 2 + (b ^ 1)].set(x * 2 + a);
					}
				}
			}
		}
	}
	L(k, 0, m * 2 - 1) 
		L(i, 0, m * 2 - 1) if(e[i][k]) 
			e[i] |= e[k];
	L(i, 0, m - 1) 
		odd.set(i * 2);
	dfs(0, bitset < N > ());
	cout << cons << '\n';
	L(x, 0, m - 1) {
		L(y, 0, m - 1) {
			L(a, 0, 1) {
				L(b, 0, 1) {
					if(fb[x][y][a][b]) {
						cout << x << ' ' << y << ' ' << a + b * 2 + 1 << '\n'; 
					}
				}
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

input:

2 1
1
0

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #2:

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

input:

3 3
101
011
111

output:

12
0 0 3
0 0 2
0 1 4
0 2 3
0 2 4
1 1 3
1 1 2
1 2 3
1 2 4
2 2 3
2 2 2
2 2 4

result:

ok Kout = 12, Kans = 6

Test #3:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

2 1
0
1

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #4:

score: 0
Accepted
time: 2ms
memory: 3476kb

input:

2 1
0
1

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #5:

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

input:

2 1
1
0

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #6:

score: 0
Accepted
time: 2ms
memory: 3612kb

input:

2 1
0
1

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #7:

score: 0
Accepted
time: 2ms
memory: 3496kb

input:

2 1
0
1

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #8:

score: 0
Accepted
time: 2ms
memory: 3472kb

input:

2 1
1
0

output:

2
0 0 3
0 0 2

result:

ok Kout = 2, Kans = 0

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 3480kb

input:

1 1
1

output:

3
0 0 3
0 0 2
0 0 4

result:

wrong answer Integer parameter [name=K] equals to 3, violates the range [-1, 2]