QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842346#9627. 算术creeshAC ✓1ms3848kbC++203.9kb2025-01-04 11:55:372025-01-04 11:55:38

Judging History

This is the latest submission verdict.

  • [2025-01-04 11:55:38]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3848kb
  • [2025-01-04 11:55:37]
  • Submitted

answer

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using db = double;
using ull = unsigned long long;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int mod = 998244353;
const int N = 3e5 + 100;
const int M = 1e6 + 100;
const db eps = 1e-6;

template<typename T>
void add(T& x, const T& y) {if((x += y) >= mod) x -= mod;}
template<typename T>
void dec(T& x, const T& y) {if((x -= y) < 0) x += mod;}
template<typename T>
void cmax(T& x, const T& y) {if(y > x) x = y;}
template<typename T>
void cmin(T& x, const T& y) {if(y < x) x = y;}

inline char get(void){
    static char buf[1 << 20], *p1 = buf, *p2 = buf;
    if (p1 == p2){
        p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin);
        if (p1 == p2) return EOF;
    }
    return *p1++;
}

template <typename T>
inline void read(T &x){
    x = 0;
    static char c;
    bool minus = false;
    for (; !(c >= '0' && c <= '9'); c = get()) if (c == '-')
        minus = true;
    for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = get());
    if (minus) x = -x;
}

int lowbit(int x){ return x & (-x);}

ll lcm(ll a, ll b){
    ll g = __gcd(a, b);
    return a / g * b;
}

struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return (x ^ (x >> 31));
    }

    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// unordered_map<int, int, custom_hash> mp;

ll qpow(ll x, ll a, int k = mod){
    ll base = x, rt = 1;
    while (a){
        if (a & 1) rt *= base, rt %= k;
        base *= base, base %= k;
        a >>= 1;
    }
    return rt;
}

vector<ll> fac, ifac;

ll inv(ll a){
    if (a < 0) a += mod;
    return qpow(a, mod - 2);
}

void init_fac(){
    fac.resize(N), ifac.resize(N);
    fac[0] = fac[1] = 1;
    for (int i = 2; i < N; i++) fac[i] = fac[i - 1] * i % mod;
    ifac[N - 1] = inv(fac[N - 1]);
    for (int i = N - 2; i >= 0; i--) ifac[i] = ifac[i + 1] * (i + 1) % mod;
}

ll C(int n, int m){
    return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

vector<int> prime, np, divi;

void init_prime(){
    np.resize(N);
    divi.resize(N);
    for (int i = 2; i < N; i++) {
        if (!np[i]){
            prime.push_back(i);
            divi[i] = i;
        }
        for (auto v : prime){
            if (v * i >= N) break;
            np[v * i] = 1;
            divi[v * i] = v;
            if (i % v == 0) break;
        }
    }
}

void init(){
    // init_prime();
    // init_fac();
}

void solve(){
    int n = 9;
    vector a(n + 2, 0ll);
    for (int i = 1; i <= n; i++) cin >> a[i];

    auto v = min(a[1], a[2]);
    a[3] += v, a[1] -= v, a[2] -= v;
    a[3] += a[1] / 3; a[1] %= 3;
    a[2] += a[1] / 2; a[1] %= 2;
    
    if (a[1]) for (int i = 2; i <= n; i++)
        if(a[i]) {a[i]--, a[i + 1]++; break;}
    a[1] = 0;
    
    // for (int i = 1; i <= 10; i++) cerr << a[i] << ' '; cerr << '\n';

    ll ans = 1;
    for (int i = 1; i <= 10; i++) ans = ans * qpow(i, a[i]) % mod;
    cout << ans << '\n';
}

int main(){
    // cerr << inv(2) << endl;
    // clock_t st = clock(), ed;
#ifndef ONLINE_JUDGE
    freopen("1.in", "r", stdin);
    freopen("my.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // srand(114514);
    init();
    int t = 1;
    cout << setprecision(15) << fixed;
    cerr << setprecision(2) << fixed;
    cin >> t;
    // read(t);
    while(t--) {
        solve();
    }
    // ed = clock();
    // double endtime=(double)(ed-st)/CLOCKS_PER_SEC;
    // cout<<"Total time:"<<endtime<<endl;
    // system("pause");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3564kb

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: 3568kb

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