結果

問題 No.1546 [Cherry 2nd Tune D] 思ったよりも易しくない
ユーザー inksamuraiinksamurai
提出日時 2021-06-13 02:46:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,878 bytes
コンパイル時間 1,277 ms
コンパイル使用メモリ 108,052 KB
実行使用メモリ 9,192 KB
最終ジャッジ日時 2024-12-20 01:42:58
合計ジャッジ時間 16,751 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 48
権限があれば一括ダウンロードができます

ソースコード

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) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
using namespace std;

const int 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;
}

int n;

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

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

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

	cout<<ans<<"\n";

 
/*
*/
 
    return 0;   
}
0