結果

問題 No.2045 Two Reflections
ユーザー shinchanshinchan
提出日時 2023-10-09 21:24:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 2,558 bytes
コンパイル時間 2,395 ms
コンパイル使用メモリ 218,196 KB
実行使用メモリ 8,644 KB
最終ジャッジ日時 2023-10-09 21:24:47
合計ジャッジ時間 3,830 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 13 ms
5,120 KB
testcase_04 AC 11 ms
4,668 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 7 ms
4,616 KB
testcase_07 AC 10 ms
4,548 KB
testcase_08 AC 7 ms
4,352 KB
testcase_09 AC 18 ms
5,960 KB
testcase_10 AC 16 ms
5,880 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 32 ms
8,644 KB
testcase_21 AC 4 ms
4,352 KB
testcase_22 AC 4 ms
4,356 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 4 ms
4,352 KB
testcase_25 AC 4 ms
4,352 KB
testcase_26 AC 3 ms
4,352 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 4 ms
4,356 KB
testcase_29 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modinv(long long a, long long MOD) {
    long long b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; std::swap(a, b);
        u -= t * v; std::swap(u, v);
    }
    u %= MOD; 
    if (u < 0) u += MOD;
    return u;
}

long long modpow(long long a, long long n, long long MOD) {
    long long res = 1;
    a %= MOD;
    if(n < 0) {
        n = -n;
        a = modinv(a, MOD);
    }
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

struct UnionFind {
    vector<int> par;
    UnionFind(int n) :par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool connect(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};



vector<pair<ll, ll>> prime(ll n) {
    ll m = n;
    vector<pair<ll, ll>> v;
    for(ll i = 2; i * i <= n; i ++) {
        ll num = 0;
        while(m % i == 0) {
            num ++;
            m /= i;
        }
        if(num) v.push_back({i, num});
    }
    if(m > 1) v.push_back({m, 1});
    return v;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, p, q;
    cin >> n >> p >> q;

    if(p == 1) {
        if(q == 1) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        } 
        return 0;
    } else if(q == 1) {
        cout << 2 << endl;
        return 0;
    }
    vector<int> ord(n);
    iota(all(ord), 0);
    reverse(ord.begin(), ord.begin() + p);
    reverse(ord.begin() + n - q, ord.end());
    UnionFind uf(n);
    rep(i, n) uf.connect(i, ord[i]);
    set<int> st;
    rep(i, n) st.insert(uf.root(i));
    map<ll, ll> mp;
    foa(e, st) {
        for(auto [x, y] : prime(uf.size(e))) {
            mp[x] = max(mp[x], y);
        }
    }
    ll ans = 2;
    for(auto [x, y] : mp) {
        ans *= modpow(x, y, MOD998);
        ans %= MOD998;
    }
    cout << ans << endl;
    return 0;
}
0