結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-06-18 23:43:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 479 ms / 2,000 ms
コード長 2,020 bytes
コンパイル時間 4,018 ms
コンパイル使用メモリ 202,056 KB
実行使用メモリ 8,084 KB
最終ジャッジ日時 2023-09-08 17:22:26
合計ジャッジ時間 25,906 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 167 ms
4,772 KB
testcase_14 AC 427 ms
7,244 KB
testcase_15 AC 221 ms
5,232 KB
testcase_16 AC 216 ms
5,224 KB
testcase_17 AC 160 ms
4,648 KB
testcase_18 AC 306 ms
6,148 KB
testcase_19 AC 283 ms
6,016 KB
testcase_20 AC 346 ms
6,404 KB
testcase_21 AC 14 ms
4,380 KB
testcase_22 AC 305 ms
6,228 KB
testcase_23 AC 253 ms
5,664 KB
testcase_24 AC 51 ms
4,380 KB
testcase_25 AC 446 ms
7,472 KB
testcase_26 AC 466 ms
7,868 KB
testcase_27 AC 221 ms
5,288 KB
testcase_28 AC 467 ms
7,776 KB
testcase_29 AC 467 ms
7,776 KB
testcase_30 AC 467 ms
7,780 KB
testcase_31 AC 467 ms
7,916 KB
testcase_32 AC 465 ms
7,812 KB
testcase_33 AC 466 ms
7,804 KB
testcase_34 AC 468 ms
7,924 KB
testcase_35 AC 468 ms
7,732 KB
testcase_36 AC 468 ms
7,864 KB
testcase_37 AC 466 ms
7,800 KB
testcase_38 AC 467 ms
7,848 KB
testcase_39 AC 467 ms
7,732 KB
testcase_40 AC 466 ms
8,012 KB
testcase_41 AC 468 ms
7,752 KB
testcase_42 AC 467 ms
7,680 KB
testcase_43 AC 404 ms
7,724 KB
testcase_44 AC 404 ms
7,880 KB
testcase_45 AC 402 ms
7,708 KB
testcase_46 AC 403 ms
8,084 KB
testcase_47 AC 404 ms
7,852 KB
testcase_48 AC 479 ms
7,724 KB
testcase_49 AC 468 ms
7,828 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll modc = 998244353;
class mint {
    ll x;
public:
    mint(ll x=0) : x((x%modc+modc)%modc) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += modc-a.x) >= modc) x -= modc;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= modc;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(modc-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    bool operator == (const mint& a) const{
        return x == a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
    friend istream& operator>>(istream& ip, mint &m) {
        ll t;
        ip >> t;
        m = mint(t);
        return ip;
    }
};

int main(){

    ll N;
    mint ans=0, P=1, Q, M=0;
    cin >> N;
    vector<mint> T(N), V(N);
    for (int i=0; i<N; i++){
        cin >> T[i] >> V[i];
        M += T[i];
    }

    auto f=[&] (mint x) -> mint{
        mint res=mint(12).inv();
        res *= x*(x+1);
        res *= x+2;
        res *= (M*4+3-x*3);

        return res;
    };

    for (int i=0; i<N; i++){
        Q = P+T[i]-1;
        ans += V[i] * (f(Q)-f(P-1));
        P = Q+1;
    }

    cout << ans/2 << endl;
}
0