結果

問題 No.2488 Mod Sum Maximization
ユーザー binapbinap
提出日時 2023-09-29 23:05:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 3,979 ms
コンパイル使用メモリ 228,416 KB
実行使用メモリ 9,008 KB
最終ジャッジ日時 2023-09-29 23:06:00
合計ジャッジ時間 8,099 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 110 ms
8,912 KB
testcase_05 WA -
testcase_06 AC 104 ms
8,544 KB
testcase_07 WA -
testcase_08 AC 105 ms
8,600 KB
testcase_09 AC 82 ms
7,240 KB
testcase_10 WA -
testcase_11 AC 5 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 66 ms
6,640 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 89 ms
7,952 KB
testcase_20 AC 100 ms
8,024 KB
testcase_21 AC 94 ms
8,040 KB
testcase_22 AC 104 ms
8,576 KB
testcase_23 AC 108 ms
8,828 KB
testcase_24 WA -
testcase_25 AC 4 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 57 ms
5,868 KB
testcase_28 AC 58 ms
5,984 KB
testcase_29 AC 56 ms
6,108 KB
testcase_30 AC 36 ms
4,884 KB
testcase_31 AC 10 ms
4,380 KB
testcase_32 AC 88 ms
7,452 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 104 ms
8,480 KB
testcase_35 AC 35 ms
4,992 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef pair<int,int> P;
typedef long double ld;

int main(){
	int n;
	cin >> n;
	vl a(n);
	rep(i, n) cin >> a[i];
	if(n <= 5){
		
		ll ans = 0;
		vi perm(n);
		rep(i, n) perm[i] = i;
		vi q(n);
		rep(i, n) q[i] = i;
		do{
		ll tmp = 0;
			rep(i, n) tmp += a[perm[i]] % a[perm[(i + 1) % n]];
			if(tmp > ans){
				ans = tmp;
				q = perm;
			}
		}while(next_permutation(perm.begin(), perm.end()));
		cout << ans << "\n";
		return 0;
	}
	
	ll base = 0;
	rep(i, n) base += a[i] % a[(i + 1) % n];
	ll ans = base;
	vl b(n);
	rep(i, n) b[i] = a[n - 1] % a[i];
	vi left(n);
	rep(i, n){
		if(i == 0) continue;
		if(b[left[i - 1]] < b[i]) left[i] = i;
		else left[i] = left[i - 1];
	}
	for(int j = 0; j < n - 1; j++){
		ll tmp = base;
		tmp -= a[n - 1] % a[0];
		tmp -= a[j] % a[(j + 1) % n];
		tmp += a[n - 1] % a[left[j]];
		tmp += a[j] % a[0];
		ans = max(tmp, ans);
//		cout << tmp << "\n";
	}
	cout << ans;
	return 0;
}
0