QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101649#6380. LaLa and Divination Magicrunewrz#WA 3ms9796kbC++202.3kb2023-04-30 16:52:592023-04-30 16:53:02

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 16:53:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9796kb
  • [2023-04-30 16:52:59]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define LL long long
#define ULL unsigned LL
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
using namespace std;
LL read() {
	LL x = 0,y = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') y = -y; ch = getchar();}
	while (isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();} return x*y;
}
namespace qiqi {
	const int N = 2005,P[2] {(int)1e9+7,(int)1e9+9},B = 3; int n,m,can[N],pw[2][N],hs[2][N][N],a[N][N];
	char s[N]; vector<pair<pii,int>> ans; bitset<N> f[N][2],g[N][2],h[N][2]; unordered_map<LL,int> vis;
	void init(int n) {
		rep(j,0,1) {
			pw[j][0] = 1; rep(i,1,n) pw[j][i] = 1LL*B*pw[j][i-1]%P[j];
		}
	}
	bool chk() {
		rep(i,1,m) rep(j,1,n) if (can[j]) {
			if ((g[i][0]&h[j][0]).none() && (g[i][1]&h[j][1]).none()) {
				LL x = (hs[0][i][n]+1LL*(1-2*a[i][j])*pw[0][n-i]%P[0]+P[0])%P[0];
				LL y = (hs[1][i][n]+1LL*(1-2*a[i][j])*pw[1][n-i]%P[1]+P[1])%P[1];
				if (vis.find(P[1]*x+y) == vis.end()) return 1;
			}
		}
		return 1;
	}
	void main() {
		m = read(); n = read(); init(n);
		rep(i,1,m) {
			scanf("%s",s+1);
			rep(j,1,n) {
				a[i][j] = s[j]-'0';
				f[j][a[i][j]][i] = 1;
				g[i][a[i][j]][j] = 1;
				rep(k,0,1) {
					hs[k][i][j] = (1LL*B*hs[k][i][j-1]%P[k]+a[i][j])%P[k];
				}
				vis[1LL*P[1]*hs[0][i][n]+hs[1][i][n]] = 1;
			}
		}
		rep(i,1,n) {
			rep(j,1,i-1) {
				if ((f[j][0]&f[i][0]).none()) {
					ans.eb(mp(mp(j,i),4));
					h[j][0][i] = h[i][0][j] = 1;
				}
				if ((f[j][0]&f[i][1]).none()) {
					ans.eb(mp(mp(j,i),2));
					h[j][1][i] = h[i][0][j] = 1;
				}
				if ((f[j][1]&f[i][0]).none()) {
					ans.eb(mp(mp(j,i),3));
					h[j][0][i] = h[i][1][j] = 1;
				}
				if ((f[j][1]&f[i][1]).none()) {
					ans.eb(mp(mp(j,i),1));
					h[j][1][i] = h[i][1][j] = 1;
				}
			}
			can[i] = 1;
			if (f[i][0].none()) {
				ans.eb(mp(mp(i,i),4));
				can[i] = 0;
			}
			if (f[i][1].none()) {
				ans.eb(mp(mp(i,i),1));
				can[i] = 0;
			}
		}
		if (!chk()) {
			puts("-1"); return;
		}
		printf("%d\n",(int)ans.size());
		for (auto [p,c]:ans) {
			printf("%d %d %d\n",p.fi-1,p.se-1,c);
		}
	}
}
int main() {
	qiqi::main(); return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 7748kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #2:

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

input:

3 3
101
011
111

output:

6
0 1 4
0 2 4
0 2 3
1 2 4
1 2 3
2 2 4

result:

ok Kout = 6, Kans = 6

Test #3:

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

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #4:

score: 0
Accepted
time: 3ms
memory: 5696kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #5:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #6:

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

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #7:

score: 0
Accepted
time: 3ms
memory: 7700kb

input:

2 1
0
1

output:

0

result:

ok Kout = 0, Kans = 0

Test #8:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #9:

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

input:

1 1
1

output:

1
0 0 4

result:

ok Kout = 1, Kans = 1

Test #10:

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

input:

1 1
0

output:

1
0 0 1

result:

ok Kout = 1, Kans = 1

Test #11:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #12:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #13:

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

input:

2 4
0111
0010

output:

15
0 0 1
0 1 3
0 1 1
0 2 4
0 2 3
0 2 1
1 2 4
1 2 3
2 2 4
0 3 3
0 3 1
1 3 2
1 3 3
2 3 4
2 3 2

result:

ok Kout = 15, Kans = 15

Test #14:

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

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #15:

score: 0
Accepted
time: 3ms
memory: 9796kb

input:

4 2
10
11
01
00

output:

0

result:

ok Kout = 0, Kans = 0

Test #16:

score: 0
Accepted
time: 3ms
memory: 5656kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #17:

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

input:

2 4
0010
1000

output:

15
0 1 2
0 1 1
1 1 1
0 2 4
0 2 1
1 2 3
1 2 1
0 3 2
0 3 1
1 3 2
1 3 3
1 3 1
2 3 2
2 3 1
3 3 1

result:

ok Kout = 15, Kans = 15

Test #18:

score: 0
Accepted
time: 3ms
memory: 7748kb

input:

2 5
11101
00000

output:

21
0 1 2
0 1 3
0 2 2
0 2 3
1 2 2
1 2 3
0 3 2
0 3 1
1 3 2
1 3 1
2 3 2
2 3 1
3 3 1
0 4 2
0 4 3
1 4 2
1 4 3
2 4 2
2 4 3
3 4 3
3 4 1

result:

ok Kout = 21, Kans = 21

Test #19:

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

input:

5 4
0010
1001
0011
0101
1011

output:

5
0 1 1
1 2 1
0 3 3
1 3 3
2 3 4

result:

wrong answer The output contains more solutions than intended.