QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#459475 | #8830. Breaking Bad | ucup-team3734# | TL | 1ms | 3732kb | C++23 | 3.0kb | 2024-06-30 04:34:10 | 2024-06-30 04:34:11 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(), (x).end()
const int mod = 1'000'000'021;
const int ROOT = 2;
int add(int x) {
return x;
}
template<typename... T>
int add(int x, T... y) {
x += add(y...);
if (x >= mod)
x -= mod;
return x;
}
template<typename... T>
int udd(int &x, T... y) {
return x = add(x, y...);
}
template<typename... T>
int sub(int x, T... y) {
return add(x, mod - add(y...));
}
int mul(int x) {
return x;
}
template<typename... T>
int mul(int x, T... y) {
return 1ll * x * mul(y...) % mod;
}
int bin(int x, int to) {
int y = 1;
while (to) {
if (to & 1) {
y = mul(x, y);
}
to >>= 1;
x = mul(x, x);
}
return y;
}
int inv(int x) {
assert(x != 0);
return bin(x, mod - 2);
}
const int M = 1010;
const int A = 10;
const int X = bin(ROOT, (mod - 1) / 5);
mt19937 rng(123);
int rnd() {
return rng() % mod;
}
int a[M][M], pw[M][M], r[M][M];
int p[A];
int n;
void swp(int i, int j, int from=0) {
if (i == j) return;
for (int k = from; k < n; ++k)
swap(a[i][k], a[j][k]);
}
void mulmat(int i, int by, int from=0) {
for (int j = from; j < n; ++j)
a[i][j] = mul(a[i][j], by);
}
void submat(int i, int j, int by, int from=0) {
for (int k = from; k < n; ++k)
a[j][k] = sub(a[j][k], mul(a[i][k], by));
}
int det() {
int ans = 1;
for (int i = 0; i < n; ++i) {
int at = -1;
for (int j = i; j < n; ++j)
if (a[j][i] != 0) {
at = j;
break;
}
swp(i, at, i);
ans = mul(ans, a[i][i]);
mulmat(i, inv(a[i][i]), i);
for (int j = i + 1; j < n; ++j)
submat(i, j, a[j][i], i);
}
return ans;
}
void gaub() {
n = 6;
int rk = 0;
for (int i = 0; i < 5; ++i) {
int at = -1;
for (int j = rk; j < 5; ++j)
if (a[j][i] != 0) {
at = j;
break;
}
if (at == -1) {
assert(!"omg matrix rank not 5");
continue;
}
swp(rk, at);
mulmat(rk, inv(a[rk][i]));
for (int j = 0; j < 5; ++j)
if (j != rk)
submat(rk, j, a[j][i]);
++rk;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
cin >> pw[i][j];
r[i][j] = rnd();
}
for (int to = 0; to < 5; ++to) {
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
a[i][j] = mul(r[i][j], bin(X, to * pw[i][j]));
p[to] = det();
// cerr << p[to] << " ";
}
// cerr << "\n";
for (int i = 0; i < 5; ++i) {
for (int j = 0; j < 5; ++j)
a[i][j] = bin(X, i * j);
a[i][5] = p[i];
}
n = 6;
gaub();
// cerr << "poly: ";
// for (int i = 0; i < 5; ++i)
// cerr << a[i][5] << " ";
// cerr << "\n";
for (int i = 0; i < 5; ++i)
cout << (a[i][5] == 0 ? 'N' : 'Y');
cout << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3596kb
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: 0ms
memory: 3576kb
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: 0
Accepted
time: 0ms
memory: 3732kb
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:
NYNNY
result:
ok "NYNNY"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
10 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 3 3 3 0 2 3 0 3 2 4 4 4 4 1 3 4 1 4 3 0 2 2 2 4 1 2 4 2 1 3 2 2 2 4 1 3 4 2 1 3 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 2 2 2 4 1 2 4 2 1 3 4 4 4 1 3 4 1 1 3 0
output:
YYYNY
result:
ok "YYYNY"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3732kb
input:
10 1 2 0 4 2 3 4 0 2 3 0 1 4 3 1 2 3 4 1 2 4 0 3 2 0 1 2 3 0 1 1 2 0 4 2 3 4 0 2 3 3 4 2 1 4 0 1 2 4 0 0 1 4 3 1 2 3 4 1 2 2 3 1 0 3 4 0 1 3 4 3 1 1 1 4 0 1 2 4 0 1 2 0 4 2 3 4 0 2 3 1 3 0 4 2 3 4 0 2 3
output:
NYYYY
result:
ok "NYYYY"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
10 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 2 3 4 2 1 1 4 3 4 1 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4
output:
NYNNN
result:
ok "NYNNN"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
10 4 1 3 1 2 0 3 2 4 4 0 2 4 2 3 1 4 3 0 0 1 1 1 1 2 0 3 2 4 1 2 4 1 4 0 3 1 0 2 2 1 3 0 3 4 2 0 4 1 1 2 4 1 4 0 3 1 0 2 2 2 4 1 4 0 3 1 0 2 2 0 2 4 2 3 1 4 3 0 0 3 0 2 1 1 4 2 1 3 3 4 1 3 1 2 0 3 2 4 4
output:
YYYYY
result:
ok "YYYYY"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
10 1 2 0 2 4 2 3 1 2 1 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 0 1 4 1 3 1 2 0 1 0
output:
NNNYN
result:
ok "NNNYN"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 1 4 1 2 1 3 3 2 1 2 0 3 0 1 0 2 2 1 0 1 0 4 0 3 0 2 2 1 0 1 1 4 1 2 1 3 3 2 1 2 4 2 4 0 4 1 1 0 4 0 1 1 1 4 1 0 3 2 1 2 0 0 0 1 0 2 2 1 0 1 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3
output:
YYYYY
result:
ok "YYYYY"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
10 1 2 0 1 4 0 1 2 2 2 1 2 0 1 4 3 1 2 2 2 0 1 4 0 3 1 0 1 1 1 1 2 0 1 4 3 1 2 2 2 3 4 2 3 1 4 3 4 4 4 0 1 4 0 3 1 0 1 1 1 4 0 3 4 2 0 4 0 0 0 3 4 2 3 1 4 3 4 4 4 4 0 3 4 2 0 4 0 0 0 0 1 4 0 3 1 0 1 1 1
output:
YNYNY
result:
ok "YNYNY"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
10 1 3 0 0 2 1 3 4 3 3 3 3 0 0 4 1 3 4 3 3 1 1 3 3 2 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 4 1 3 3 0 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 0 2 4 4 1 0 2 3 2 2 3 0 2 2 4 3 0 1 0 0 3 0 2 2 4 3 0 1 0 0 4 2 4 4 1 0 2 3 2 2
output:
YYYNY
result:
ok "YYYNY"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
10 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 1 4 2 0 2 4 4 4 3 0 3 3 4 2 4 1 1 1 0 2 3 1 4 2 4 1 1 1 0 2 4 2 0 3 0 2 2 2 1 3 3 1 4 2 4 1 1 1 0 2 1 4 2 0 2 4 4 4 3 0
output:
YNYNN
result:
ok "YNYNN"
Test #15:
score: -100
Time Limit Exceeded
input:
1000 3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...