結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー inksamuraiinksamurai
提出日時 2021-06-13 02:48:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 1,885 bytes
コンパイル時間 1,249 ms
コンパイル使用メモリ 105,120 KB
実行使用メモリ 13,152 KB
最終ジャッジ日時 2023-08-23 01:12:28
合計ジャッジ時間 16,650 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 136 ms
5,092 KB
testcase_14 AC 344 ms
11,624 KB
testcase_15 AC 179 ms
8,884 KB
testcase_16 AC 174 ms
7,780 KB
testcase_17 AC 129 ms
5,080 KB
testcase_18 AC 247 ms
7,444 KB
testcase_19 AC 227 ms
8,572 KB
testcase_20 AC 281 ms
7,636 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 248 ms
8,612 KB
testcase_23 AC 205 ms
7,768 KB
testcase_24 AC 41 ms
4,380 KB
testcase_25 AC 359 ms
11,412 KB
testcase_26 AC 374 ms
11,328 KB
testcase_27 AC 179 ms
7,708 KB
testcase_28 AC 379 ms
12,624 KB
testcase_29 AC 375 ms
11,460 KB
testcase_30 AC 376 ms
11,584 KB
testcase_31 AC 376 ms
11,940 KB
testcase_32 AC 375 ms
11,572 KB
testcase_33 AC 375 ms
12,328 KB
testcase_34 AC 375 ms
11,396 KB
testcase_35 AC 379 ms
11,836 KB
testcase_36 AC 375 ms
12,248 KB
testcase_37 AC 379 ms
11,680 KB
testcase_38 AC 378 ms
11,248 KB
testcase_39 AC 379 ms
12,664 KB
testcase_40 AC 378 ms
11,832 KB
testcase_41 AC 379 ms
11,548 KB
testcase_42 AC 379 ms
12,232 KB
testcase_43 AC 356 ms
11,500 KB
testcase_44 AC 358 ms
13,152 KB
testcase_45 AC 356 ms
11,540 KB
testcase_46 AC 358 ms
12,128 KB
testcase_47 AC 357 ms
11,692 KB
testcase_48 AC 379 ms
11,816 KB
testcase_49 AC 379 ms
11,948 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (ll)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <ll,ll>
#define rep(i,n) for(ll i = 0 ; i < n ; i++) 
#define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(ll i = x ; i < n ; i++)
#define vi vector <ll> 
#define vec(...) vector<__VA_ARGS__>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
using namespace std;

const ll max_n = 103002;
ll mod=998244353;
ll sub(ll a , ll b){
  a%=mod; b%=mod;
  return (((a-b)%mod)+mod)%mod;
}
ll prod(ll a , ll b){
  a%=mod; b%=mod;
  return ((a*b)%mod);
}
ll add(ll a , ll b){
  a%=mod; b%=mod;
  return (a+b)%mod;
}
ll binpow(ll a, ll b) {  
  a %= mod; ll res = 1; 
  while (b) { if (b%2) res = res * a % mod; a = a * a % mod; b /= 2; } 
  return res % mod;
}
ll f(ll n,ll m) {
	ll p0 = prod(n,add(prod(n,n),add(prod(3,n),2)));
	// ll p1 = sub(prod(4,m),add(prod(3,n),3));
	ll p1=sub(prod(4,m),add(3,prod(3,n)));
	return (prod(p0,4*m-3*n+3))*binpow(24,mod-2)%mod;
}

ll n;

int main(){
fcin;
	cin>>n;

	vec(pii) a;
	ll m=0;
	rep(_,n) {
		ll t,v;
		cin>>t>>v;
		a.pb({t,v});
		m=add(m,t);
	}

	ll ans=0,j=0;
	rep(i,n) {
		ll x=f(add(j,a[i].fi),m);
		x = sub(x,f(j,m));
		ans=add(ans,prod(x,a[i].se));
		j=add(j,a[i].fi);
	}

	cout<<ans<<"\n";

 
/*
*/
 
    return 0;   
}
0