QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#753330 | #9627. 算术 | D12EQD# | AC ✓ | 1ms | 3780kb | C++17 | 5.1kb | 2024-11-16 12:24:31 | 2024-11-16 12:24:38 |
Judging History
answer
#include <bits/stdc++.h>
#define min(a,b) (a > b ? b : a)
#define max(a,b) (a < b ? b : a)
#define YES (cout << "YES" << endl)
#define NO (cout << "NO" << endl)
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define rrep(a, b, c) for (a = b; a >= c; a--)
#define rep(a, b, c) for (a = b; a <= c; a++)
#define int long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
using namespace std;
typedef double db;
typedef pair<int,int> pii;
typedef array <int,3> a3;
const db eps = 1e-7;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 200010;
template<long long mod>
struct mint{
long long qmi(long long a,long long b){
long long res = 1;
while (b){
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
long long inv(long long x){
return qmi(x,mod-2);
}
long long val;
mint(long long val_) : val(val_ % mod) { }
mint(signed val_) : val(val_ % mod) { }
mint() { val = 0;}
mint operator+(const mint &t){
return mint((t.val + val) % mod);
}
mint operator-(const mint &t){
return mint((val - t.val + mod) % mod);
}
mint operator*(const mint &t){
return mint((val * t.val) % mod);
}
mint operator/(const mint &t){
return mint((val * (inv(t.val))) % mod);
}
void operator+=(const mint &t){
val = (val + t.val) % mod;
}
void operator-=(const mint &t){
val = (val - t.val + mod) % mod;
}
void operator*=(const mint &t){
val = (val * t.val) % mod;
}
void operator/=(const mint &t){
val = (val * inv(t.val)) % mod;
}
mint operator+(long long t){
t = ((t % mod) + mod) % mod;
return mint((t + val) % mod);
}
mint operator-(long long t){
t = ((t % mod) + mod) % mod;
return mint((val - t + mod) % mod);
}
mint operator*(long long t){
t = ((t % mod) + mod) % mod;
return mint((val * t) % mod);
}
mint operator/(long long t){
t = ((t % mod) + mod) % mod;
return mint((val * (inv(t))) % mod);
}
void operator+=(long long t){
t = ((t % mod) + mod) % mod;
val = (val + t) % mod;
}
void operator-=(long long t){
t = ((t % mod) + mod) % mod;
val = (val - t + mod) % mod;
}
void operator*=(long long t){
t = ((t % mod) + mod) % mod;
val = (val * t) % mod;
}
void operator/=(long long t){
t = ((t % mod) + mod) % mod;
val = (val * inv(t)) % mod;
}
mint operator+(signed t){
t = ((t % mod) + mod) % mod;
return mint((t + val) % mod);
}
mint operator-(signed t){
t = ((t % mod) + mod) % mod;
return mint((val - t + mod) % mod);
}
mint operator*(signed t){
t = ((t % mod) + mod) % mod;
return mint((val * t) % mod);
}
mint operator/(signed t){
t = ((t % mod) + mod) % mod;
return mint((val * (inv(t))) % mod);
}
void operator+=(signed t){
t = ((t % mod) + mod) % mod;
val = (val + t) % mod;
}
void operator-=(signed t){
t = ((t % mod) + mod) % mod;
val = (val - t + mod) % mod;
}
void operator*=(signed t){
t = ((t % mod) + mod) % mod;
val = (val * t) % mod;
}
void operator/=(signed t){
t = ((t % mod) + mod) % mod;
val = (val * inv(t)) % mod;
}
void operator=(const int &x){
val = ((x % mod) + mod) % mod;
}
friend std::ostream &operator<<(std::ostream &os, mint a) {
a.val = ((a.val % mod) + mod) % mod;
return os << a.val;
}
};
typedef mint<998244353> Mint;
void solve(){
int n = 9;
int i, j;
vector <int> c(15);
rep(i,1,n) cin >> c[i];
Mint ans = 1;
Mint qmi = 0;
int res = 0;
int cost = min(c[1], c[2]);
c[1] -= cost;
c[2] -= cost;
c[3] += cost;
c[3] += c[1] / 3;
c[1] %= 3;
c[2] += c[1] / 2;
c[1] %= 2;
bool isok = 0;
rep(i,2,9){
if (c[i]){
c[i] -= c[1];
c[i + 1] += c[1];
c[1] = 0;
isok = 1;
break;
}
}
// cout << "ANS : ";
if (!isok){
if (c[1]) cout << 1 << endl;
else cout << 0 << endl;
return;
}
rep(i,2,n + 1){
ans *= qmi.qmi(i, c[i]);
}
// rep(i,1,n + 1){
// cout << c[i] << ' ';
// }
// cout << endl;
cout << ans << endl;
}
/*
100
2 2 2 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0
2 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
5 3 0 0 0 0 0 0 0
4 1 1 1 0 0 0 0 0
1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 2
99 88 77 66 55 44 33 22 11
100 90 80 70 60 50 40 30 20
*/
signed main(){
cin.tie(0);
IOS;
int T = 1;
cin >> T;
while (T --){
solve();
}
// system("pause");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
7 5 3 0 0 0 0 0 0 0 4 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 2 99 88 77 66 55 44 33 22 11 100 90 80 70 60 50 40 30 20
output:
54 108 1 10 90 90553232 143532368
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
1000 22 80 50 23 35 71 81 70 96 40 33 36 2 51 52 96 5 32 56 35 85 13 58 80 26 14 31 60 21 8 19 79 5 94 44 33 85 55 10 59 76 98 28 22 69 14 72 40 14 100 68 5 18 69 95 42 51 0 32 97 37 34 85 54 33 18 40 34 10 72 72 68 81 47 80 23 23 68 40 3 71 58 7 36 79 89 83 5 68 16 30 3 82 79 35 28 30 55 88 17 86 2...
output:
376701872 321820208 765709043 819408880 639261805 521201354 7172464 780360907 240853384 151457742 298466126 416189734 124742738 161566750 493291429 481038778 409158325 951979430 783007793 438976523 440485591 163247072 78098984 275527515 308024444 168349368 423889166 168234582 827159852 914298923 465...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
1000 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0...
output:
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 9 10 4 6 8 10 12 14 16 18 9 12 15 18 21 24 27 16 20 24 28 32 36 25 30 35 40 45 36 42 48 54 49 56 63 64 72 81 53234520 78732 944784 17744840 53234520 688747536 141958720 19131876 4374 9726857 668738521 35489680 11664 79851780 8748 104630853 551437603 234594227 96996101...
result:
ok 1000 lines