結果

問題 No.2284 Assembly
ユーザー shobonvip
提出日時 2023-04-28 22:02:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 751 bytes
コンパイル時間 4,457 ms
コンパイル使用メモリ 252,052 KB
最終ジャッジ日時 2025-02-12 15:11:10
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

int main(){
	int n; cin >> n;
	vector<ll> a(n), b(n);
	ll asum = 0;
	ll bsum = 0;
	for (int i=0; i<n; i++){
		cin >> a[i] >> b[i];
		asum += a[i];
		bsum += b[i];
	}
	ll anow = 0;
	ll bnow = 0;
	ll afront = 0;
	ll bfront = 0;
	ll aback = 0;
	ll bback = 0;
	ll ans = 0;
	for (int i=0; i<n; i++){
		anow += a[i];
		bnow += b[i];
		if (a[i] * (bsum - bnow) < b[i] * (asum - anow)){
			ans += a[i] * bfront + b[i] * (anow - afront - a[i]);
			afront += a[i];
			bfront += b[i];
		}else{
			ans += a[i] * (bnow - bback - b[i]) + b[i] * aback;
			aback += a[i];
			bback += b[i];
		}
	}
	cout << ans << endl;
}
0