QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#849399#8830. Breaking BadzhoukangyangWA 1ms11888kbC++142.8kb2025-01-09 15:09:332025-01-09 15:09:33

Judging History

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

  • [2025-01-09 15:09:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11888kb
  • [2025-01-09 15:09:33]
  • 提交

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 ll long long 
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a)) 
#define pb emplace_back
using namespace std;
const int N = 2007, p = 5, mod = 1019491111;
int qpow(int x, int y = mod - 2) {
	int res = 1;
	for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
	return res;
}
const int w = qpow(6, (mod - 1) / p);
mt19937_64 rng;
int val1[23][N];
int val2[23][N];
int n;
int pw[N];
int a[N][N], eval[N][N];
int mul[N][N];
int mov;
int v1[N], v2[N];
int f[N][N], pv[N], cv[N];
int det(int m) {
	int ns = 1;
	L(i, 1, m) {
		int cs = 0;
		L(j, i, m) if(f[j][i]) {
			cs = j;
			break;
		}
		if(!cs) return 0;
		if(cs != i) ns = mod - ns, swap(f[i], f[cs]);
		ns = (ll) ns * f[i][i] % mod;
		int Iv = qpow(f[i][i]);
		L(j, i, m) f[i][j] = (ll) f[i][j] * Iv % mod;
		L(j, i + 1, m) R(k, m, i) 
			(f[j][k] += mod - (ll) f[i][k] * f[j][i] % mod) %= mod; 
	}
	return ns;
}


int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	pw[0] = 1;
	L(i, 1, p) pw[i] = (ll)pw[i - 1] * w % mod;
	cin >> n;
	L(i, 1, n) {
		L(j, 1, n) {
			cin >> a[i][j];
		}
	}
	L(i, 1, n) L(j, 1, n) mul[i][j] = rng() % mod;
	int cur = 0;
	L(i, 1, n) {
		i = max(i, cur + 2);
		if(cur >= p * 2) {
			L(i, 1, p) cout << "Y";
			return 0;
		}
		L(j, cur + 2, n) {
			if((a[i][j] + a[cur + 1][cur + 1] - a[cur + 1][i] - a[cur + 1][j]) % p != 0) {
				L(p, 1, n) swap(a[i][p], a[cur + 2][p]);
				L(p, 1, n) swap(a[p][j], a[p][cur + 2]);
				--i;
				cur += 2;
				break;
			}
		}
	}
	L(i, 1, n) {
		int dec = a[i][cur + 1];
		(mov += dec) %= p;
		L(j, 1, n) (a[i][j] += p - dec) %= p;
	}
	L(i, 1, n) {
		int dec = a[cur + 1][i];
		(mov += dec) %= p;
		L(j, 1, n) (a[j][i] += p - dec) %= p;
	}
	L(i, 1, cur) {
		L(j, 1, n) {
			val1[i][j] = rng() % mod;
			val2[i][j] = rng() % mod;
		}
	}
	L(d, 0, p - 1) {
		L(i, 1, n) L(j, 1, (i <= cur ? n : cur)) eval[i][j] = (ll) pw[(ll)d * a[i][j] % p] * mul[i][j] % mod;
		L(i, 1, cur) L(j, 1, cur) f[i][j] = eval[i][j];
		L(t, 1, cur) {
			me(v1, 0);
			me(v2, 0);
			L(i, cur + 1, n) L(j, 1, cur) (v1[j] += (ll)eval[i][j] * val1[t][i] % mod) %= mod;
			L(i, cur + 1, n) L(j, 1, cur) (v2[j] += (ll)eval[j][i] * val2[t][i] % mod) %= mod;
			L(i, 1, cur) 
				L(j, 1, cur) 
					(f[i][j] += (ll)v2[i] * v1[j] % mod) %= mod;
		}
		pv[d] = det(cur);
	}
	L(x, 0, p - 1) {
		L(y, 0, p - 1) {
			(cv[x] += (ll)pw[p - x * y % p] * pv[y] % mod) %= mod;
		}
	}
	L(i, 0, p - 1) cout << (cv[(i + p - mov) % p] ? 'Y' : 'N');
	return 0;
}

詳細信息

Test #1:

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

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

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

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

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

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

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

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

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

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

YYYYY

result:

wrong answer 1st words differ - expected: 'NYNNY', found: 'YYYYY'