QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101743 | #6325. Peaceful Results | w4p3r | RE | 421ms | 43068kb | C++20 | 4.7kb | 2023-04-30 23:52:12 | 2023-04-30 23:52:15 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define db double
#define ve vector<int>
#define pa pair<int,int>
#define fr first
#define sd second
#define pb push_back
#define mp make_pair
#define MEM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
inline ll read()
{
char ch = getchar();
ll s = 0, w = 1;
while (ch < '0' || ch > '9') {if (ch == '-')w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {s = s * 10 + ch - '0'; ch = getchar();}
return s * w;
}
#define N 1500010
int Maxn;
const int mod = 998244353;
int limit = 1, l = 0;
int A[N << 2], B[N << 2];
int r[N << 2];
int fac[N], inv[N], n;
inline int ksm(int a, int b)
{
int ans = 1;
while (b) {if (b & 1)ans = 1LL * ans * a % mod; b >>= 1; a = 1LL * a * a % mod;}
return ans;
}
inline void NTT(int a[], int type)
{
FOR(i, 0, limit - 1)if (i < r[i])swap(a[i], a[r[i]]);
for (int mid = 1; mid < limit; mid <<= 1)
{
int wn = ksm(3, (mod - 1) / (mid << 1)); if (type == -1)wn = ksm(wn, mod - 2);
for (int R = (mid << 1), j = 0; j < limit; j += R)
{
for (int k = 0, w = 1; k < mid; k++, w = 1LL * w * wn % mod)
{
int x = a[j + k], y = 1LL * w * a[j + k + mid] % mod;
a[j + k] = (x + y) % mod; a[j + k + mid] = (x + mod - y) % mod;
}
}
}
if (type == -1)
{
int inv = ksm(limit, mod - 2);
FOR(i, 0, limit - 1)a[i] = 1LL * a[i] * inv % mod;
}
}
inline vector<int> operator *(const vector<int> &a, const vector<int>&b)
{
int n = a.size(), m = b.size();
limit = 1, l = 0;
while (limit <= (n + m)) limit <<= 1, l ++;
FOR(i, 0, limit - 1)r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
FOR (i, 0, limit - 1) A[i] = (i < n ? a[i] : 0);
FOR (i, 0, limit - 1) B[i] = (i < m ? b[i] : 0);
// cerr << "GG:" << endl;
// FOR(i, 0, limit - 1)cerr << A[i] << ' '; cerr << endl;
// FOR(i, 0, limit - 1)cerr << B[i] << ' '; cerr << endl;
NTT(A, 1); NTT(B, 1);
FOR(i, 0, limit - 1)A[i] = 1LL * A[i] * B[i] % mod;
NTT(A, -1);
// FOR(i, 0, limit - 1)cerr << A[i] << ' '; cerr << endl;
vector<int>ans(limit);
FOR(i, 0, limit - 1)ans[i] = A[i];
while ((limit && (!ans[limit - 1])) || limit > Maxn + 1)limit--, ans.pop_back();
return ans;
}
vector a(10, vector<int>(10, 0));
vector b(10, vector<db>(10, 0));
db ans[10];
inline void guess()
{
FOR(i, 0, 5)
{
int p = -1;
FOR(j, i, 5)if (abs(b[j][i]) > eps) {p = j; break;}
assert(p != -1);
swap(b[p], b[i]);
FOR(j, i + 1, 5)
{
db tmp = -b[j][i] / b[i][i];
FOR(k, i, 6)b[j][k] += b[i][k] * tmp;
}
}
// FOR(i, 0, 5)
// {
// FOR(j, 0, 6)cerr << b[i][j] << ' '; cerr << '\n';
// }
REP(i, 5, 0)
{
ans[i] = b[i][6] / b[i][i];
REP(j, i - 1, 0)b[j][6] -= ans[i] * b[j][i];
}
}
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n = read();
fac[0] = 1;
FOR(i, 1, n)fac[i] = 1LL * fac[i - 1] * i % mod;
inv[0] = inv[1] = 1; FOR(i, 2, n)inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
FOR(i, 2, n)inv[i] = 1LL * inv[i] * inv[i - 1] % mod;
FOR(i, 1, 3)FOR(j, 1, 3)a[i][j] = read(); Maxn = a[1][1];
b[0] = {1, 0, 1, 0, 1, 0, a[1][2] - a[1][1]};
b[1] = {0, 1, 0, 1, 0, 1, a[1][3] - a[1][1]};
b[2] = {1, 0, 0, -1, -1, 1, a[2][2] - a[2][1]};
b[3] = {0, 1, 1, -1, -1, 0, a[2][3] - a[2][1]};
b[4] = {1, 0, -1, 1, 0, -1, a[3][2] - a[3][1]};
b[5] = {0, 1, -1, 0, 1, -1, a[3][3] - a[3][1]};
// cerr << "GG:" << '\n';
guess();
FOR(i, 0, 5)if (ans[i] - 1.0 * int(ans[i]) > eps) {cout << "0\n"; return 0;}
vector<int> p(Maxn + 1, 0), q(Maxn + 1, 0), r(Maxn + 1, 0);
FOR(i, 0, Maxn) if (i + int(ans[0]) >= 0 && i + int(ans[1]) >= 0)
{
p[i] = 1LL * inv[i] * inv[i + int(ans[0])] % mod * inv[i + int(ans[1])] % mod;
}
FOR(i, 0, Maxn) if (i + int(ans[2]) >= 0 && i + int(ans[2]) >= 0)
{
q[i] = 1LL * inv[i] * inv[i + int(ans[2])] % mod * inv[i + int(ans[3])] % mod;
}
FOR(i, 0, Maxn) if (i + int(ans[4]) >= 0 && i + int(ans[5]) >= 0)
{
r[i] = 1LL * inv[i] * inv[i + int(ans[4])] % mod * inv[i + int(ans[5])] % mod;
}
// FOR(i, 0, n)cerr << p[i] << ' '; cerr << '\n';
// FOR(i, 0, n)cerr << q[i] << ' '; cerr << '\n';
// FOR(i, 0, n)cerr << r[i] << ' '; cerr << '\n';
// cerr << ans[0] << " " << ans[1] << " " << ans[2] << " " << ans[3] << " " << ans[4] << " " << ans[5] << '\n';
p = p * q * r;
// cerr << p[2] << endl;
cout << 1LL * fac[n] * p[Maxn] % mod << '\n';
return 0;
}
/*
1 0 1 0 1 0
0 1 0 1 0 1
1 0 0 −1 −1 1
0 1 1 −1 −1 0
1 0 −1 1 0 −1
0 1 −1 0 1 −1
AP − AR
AS − AR
BP − BR
BS − BR
CP − CR
CS − CR
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11628kb
input:
2 2 0 0 1 1 0 1 0 1
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5436kb
input:
3 0 1 2 3 0 0 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 92ms
memory: 22988kb
input:
333333 111111 111111 111111 111111 111111 111111 111111 111111 111111
output:
383902959
result:
ok 1 number(s): "383902959"
Test #4:
score: 0
Accepted
time: 405ms
memory: 42984kb
input:
1500000 500000 500000 500000 500000 500000 500000 500000 500000 500000
output:
355543262
result:
ok 1 number(s): "355543262"
Test #5:
score: 0
Accepted
time: 402ms
memory: 43068kb
input:
1499999 499999 499999 500001 499999 499999 500001 499999 499999 500001
output:
934301164
result:
ok 1 number(s): "934301164"
Test #6:
score: 0
Accepted
time: 21ms
memory: 20376kb
input:
1500000 1 0 1499999 1499999 1 0 0 1499999 1
output:
1500000
result:
ok 1 number(s): "1500000"
Test #7:
score: 0
Accepted
time: 39ms
memory: 20612kb
input:
1499999 0 749999 750000 750000 0 749999 749999 750000 0
output:
713966599
result:
ok 1 number(s): "713966599"
Test #8:
score: 0
Accepted
time: 2ms
memory: 11624kb
input:
1 1 0 0 0 0 1 0 1 0
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 2ms
memory: 11568kb
input:
1 0 1 0 0 1 0 0 1 0
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 1ms
memory: 5428kb
input:
1 0 0 1 1 0 0 1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 419ms
memory: 41124kb
input:
1499999 500000 500000 499999 499999 499999 500001 499999 499999 500001
output:
617065435
result:
ok 1 number(s): "617065435"
Test #12:
score: 0
Accepted
time: 1ms
memory: 11560kb
input:
2 1 1 0 0 0 2 0 0 2
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 421ms
memory: 42988kb
input:
1500000 500000 500001 499999 499999 500000 500001 499999 500000 500001
output:
925862004
result:
ok 1 number(s): "925862004"
Test #14:
score: -100
Runtime Error
input:
629197 210878 201408 216911 145293 266423 217481 194751 220179 214267