結果

問題 No.2834 Work to Play
ユーザー 👑 potato167potato167
提出日時 2024-08-02 22:52:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,347 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 212,128 KB
実行使用メモリ 17,984 KB
最終ジャッジ日時 2024-08-02 22:53:03
合計ジャッジ時間 8,926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,948 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 8 ms
17,856 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 7 ms
17,984 KB
testcase_33 AC 4 ms
12,556 KB
testcase_34 AC 6 ms
14,456 KB
testcase_35 AC 6 ms
13,904 KB
testcase_36 AC 5 ms
10,796 KB
testcase_37 AC 4 ms
8,820 KB
testcase_38 AC 4 ms
12,828 KB
testcase_39 AC 4 ms
10,592 KB
testcase_40 AC 5 ms
13,920 KB
testcase_41 AC 6 ms
15,004 KB
testcase_42 AC 7 ms
17,356 KB
testcase_43 AC 5 ms
13,672 KB
testcase_44 AC 4 ms
7,288 KB
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,940 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 AC 7 ms
15,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
const int mod=998244353;
#define rep(i,a,b) for (ll i=(ll)(a);i<(ll)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}
template<class T> bool inside(T l,T x,T r){return l<=x&&x<r;}

#include <atcoder/modint>
using mint = atcoder::modint998244353;

mint solve2(ll K, vector<ll> B, int out = 1){
    int N = B.size();
    mint res = 0;
    rep(i, 0, N){
        res += (mint)(i + 1) * (mint)(B[i] / K);
        B[i] %= K;
    }
    if (out) cout << res.val() << " ";
    ll tmp = K;
    for (int i = N - 1; i >= 0; i--){
        if (B[i] == 0) continue;
        ll n_tmp = tmp + B[i];
        if (n_tmp > K){
            res += i + 1;
            n_tmp -= K;
        }
        tmp = n_tmp;
    }
    return res;
}

mint solve(ll N, ll A, ll K){
    mint ans = 0;
    vector<ll> p = {A};
    vector<ll> q;
    while (p.back() != 0) p.push_back((p.back() + A) % K);
    rep(i, 0, p.size()) q.push_back((A * (i + 1)) / K);
    ll L = p.size();
    // 最初の回収
    ll X = N / L, Y = N % L;
    mint base1 = 0;
    mint base2 = 0;
    mint tmp;
    rep(i, 0, L) base1 += (mint)(i + 1) * q[i];
    rep(i, 0, L) base2 += (mint)(L) * q[i];
    ans += base1 * X;
    ans += base2 * (mint)(X) * (mint)(X - 1) / 2;
    rep(i, 0, Y){
        ans += (mint)(i + 1 + X * L) * q[i];
        ans += (mint)(i + 1 + X * L) * (mint)(X) * (mint)(A * L / K);
    }
    tmp = ((mint)(L + 1) * (mint)(L)) / 2;
    tmp *= ((mint)(X) * (mint)(X - 1)) / 2;
    ans += tmp * (mint)(A * L / K);
    tmp = (mint)(L) * (mint)(A * L / K) * (mint)(L);
    tmp *= ((mint)(X - 1) * (mint)(X) * (mint)(2 * X - 1)) / 6;
    ans += tmp;
    // cout << ans.val() << " ";
    // 最後の回収
    // 2 * (K - 1) * K 台回収するループになるはず
    // 2 * K 個は流石に連続なので、そこで区切って残りを愚直
    // 2 * K 個の置き場にあるカートの総和は、2 * K * K * (L - 1) / 2L = K * ((L - 1) * K / L)
    vector<ll> r;
    rep(i, 0, 2 * K){
        r.push_back(abs((N - i) % K) * A % K);
    }
    reverse(all(r));
    base1 = solve2(K, r, 0);
    r.clear();
    rep(i, 0, N % (2 * K)) r.push_back((i + 1) * A % K);
    ans += solve2(K, r, 0);
    // cout << ans.val() << " " << base1.val() << " ";
    X = N / (K * 2);
    ans += base1 * X;
    tmp = (mint)(L - 1) * (mint)(K / L);
    ans += tmp * (mint)(X) * (N % (2 * K));
    ans += (mint)(X) * (mint)(X - 1) * (mint)(tmp) * (mint)(K);
    // 出力
    return ans;
}

// CYAN / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    rep(i, 0, t){
        ll N, A, K;
        cin >> N >> A >> K;
        vector<ll> B(N);
        rep(j, 0, N) B[j] = (j + 1) * A;
        // cout << (solve2(K, B) * 2).val() << "\n";
        cout << (solve(N, A, K) * 2).val() << "\n";
    }
}

0