結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー midri1784midri1784
提出日時 2021-06-11 23:07:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 4,098 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 169,840 KB
実行使用メモリ 8,076 KB
最終ジャッジ日時 2023-08-21 13:57:53
合計ジャッジ時間 9,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 43 ms
4,664 KB
testcase_14 AC 106 ms
7,264 KB
testcase_15 AC 55 ms
5,112 KB
testcase_16 AC 55 ms
5,416 KB
testcase_17 AC 40 ms
4,660 KB
testcase_18 AC 77 ms
6,156 KB
testcase_19 AC 71 ms
5,912 KB
testcase_20 AC 87 ms
6,468 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 75 ms
6,504 KB
testcase_23 AC 63 ms
5,804 KB
testcase_24 AC 13 ms
4,376 KB
testcase_25 AC 109 ms
7,432 KB
testcase_26 AC 112 ms
7,800 KB
testcase_27 AC 55 ms
5,284 KB
testcase_28 AC 112 ms
7,728 KB
testcase_29 AC 116 ms
7,756 KB
testcase_30 AC 113 ms
7,732 KB
testcase_31 AC 114 ms
7,860 KB
testcase_32 AC 116 ms
7,912 KB
testcase_33 AC 112 ms
7,868 KB
testcase_34 AC 115 ms
7,664 KB
testcase_35 AC 114 ms
7,868 KB
testcase_36 AC 113 ms
7,812 KB
testcase_37 AC 116 ms
7,852 KB
testcase_38 AC 114 ms
7,848 KB
testcase_39 AC 114 ms
7,852 KB
testcase_40 AC 114 ms
8,056 KB
testcase_41 AC 116 ms
7,748 KB
testcase_42 AC 116 ms
7,792 KB
testcase_43 AC 98 ms
7,676 KB
testcase_44 AC 99 ms
7,740 KB
testcase_45 AC 98 ms
7,828 KB
testcase_46 AC 99 ms
7,796 KB
testcase_47 AC 98 ms
8,076 KB
testcase_48 AC 118 ms
7,788 KB
testcase_49 AC 116 ms
7,756 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

template<long long M, typename T=long long>
struct modint {
  modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {}
  using this_type = modint<M, T>;
  T val;
  this_type operator++(int) {
    this_type ret = *this;
    val++; val %= M;
    return ret;
  }
  this_type operator--(int) {
    this_type ret = *this;
    val += M-1; val %= M;
    return ret;
  }
  this_type &operator++() {
    val++; val %= M;
    return *this;
  }
  this_type &operator--() {
    val += M-1; val %= M;
    return *this;
  }
  this_type operator+() const { return *this; }
  this_type operator-() const { return this_type(M-val); };
  friend this_type operator+(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) += rhs;
  }
  friend this_type operator-(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) -= rhs;
  }
  friend this_type operator*(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) *= rhs;
  }
  friend this_type operator/(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) /= rhs;
  }
  this_type pow(long long b) const {
    this_type ret = 1, a = *this;    
    while(b != 0) {
      if(b % 2 != 0) {
        ret *= a;
      }
      b /= 2;
      a = a * a;
    }
    return ret;
  }
  this_type inv() const {
    return pow(M-2);
  }
  this_type& operator+=(const this_type &rhs) {
    val += rhs.val; val %= M; return *this;
  }
  this_type& operator-=(const this_type &rhs) {
    val += M - rhs.val; val %= M; return *this;
  }
  this_type& operator*=(const this_type &rhs) {
    val *= rhs.val; val %= M; return *this;
  }
  this_type& operator/=(const this_type &rhs) {
    *this *= rhs.inv(); return *this;
  }
  friend bool operator==(const this_type &lhs, const this_type &rhs) {
    return lhs.val == rhs.val;
  }
  friend bool operator!=(const this_type &lhs, const this_type &rhs) {
    return lhs.val != rhs.val;
  }
  T mod() const {return M;}
};

using mi = modint<998244353>;
using vmi = vector<mi>;
using vvmi = vector<vmi>;

inline mi S0(mi v) {
  return v;
}

mi inv_2 = mi(2).inv();
mi inv_6 = mi(6).inv();
inline mi S1(mi v) {
  return v * (v + 1) * inv_2;
}

inline mi S2(mi v) {
  return v * (v + 1) * (2 * v + 1) * inv_6;
}

inline mi S3(mi v) {
  mi s = S1(v);
  return s * s;
}

inline mi F(mi v, mi L) {
  return (- S3(v) + (L - 3) * S2(v) + (3 * L - 2) * S1(v) + 2 * L * S0(v)) * inv_2;
}

inline mi G(mi l, mi r, mi L) {
  return F(r-1, L) - F(l-1, L);
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N; cin >> N;
  vi T(N), V(N);
  mi L = 0;
  REP(0, N, i) {
    RI(T[i]); RI(V[i]);
    L += T[i];
  }

  mi ans = 0;
  mi l = 0;
  REP(0, N, i) {    
    //cerr << G(l, l + T[i], V[i]).val << endl;
    ans += G(l, l + T[i], L) * mi(V[i]);
    l += T[i];
  }

  WI(ans.val);

  return 0;
}

0