QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#849340 | #8830. Breaking Bad | zhoukangyang | WA | 2ms | 9856kb | C++14 | 2.8kb | 2025-01-09 14:42:59 | 2025-01-09 14:43:08 |
Judging History
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 * 2) {
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] = pw[(ll)d * a[i][j] % p];
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][j] % mod) %= mod;
L(i, 1, cur)
L(j, 1, cur)
(f[i][j] += (ll)v1[i] * v2[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9788kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9812kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 9856kb
input:
4 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0
output:
YYYYY
result:
wrong answer 1st words differ - expected: 'YYYYN', found: 'YYYYY'