QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101650#6380. LaLa and Divination Magicrunewrz#WA 2ms7708kbC++202.3kb2023-04-30 16:58:052023-04-30 16:58:06

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:58:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7708kb
  • [2023-04-30 16:58:05]
  • 提交

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])%P[0];
				LL y = ((hs[1][i][n]+1LL*(1-2*a[i][j])*pw[1][n-i]%P[1])%P[1]+P[1])%P[1];
				if (vis.find(P[1]*x+y) == vis.end()) return 0;
			}
		}
		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: 2ms
memory: 5752kb

input:

2 1
1
0

output:

0

result:

ok Kout = 0, Kans = 0

Test #2:

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

input:

3 3
101
011
111

output:

-1

result:

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