結果

問題 No.2488 Mod Sum Maximization
ユーザー 👑 binapbinap
提出日時 2023-09-29 22:51:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,021 bytes
コンパイル時間 3,966 ms
コンパイル使用メモリ 229,240 KB
実行使用メモリ 5,476 KB
最終ジャッジ日時 2023-09-29 22:51:51
合計ジャッジ時間 7,335 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 104 ms
5,476 KB
testcase_05 WA -
testcase_06 AC 96 ms
5,212 KB
testcase_07 WA -
testcase_08 AC 99 ms
5,204 KB
testcase_09 AC 76 ms
4,620 KB
testcase_10 WA -
testcase_11 AC 4 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 61 ms
4,416 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 84 ms
5,064 KB
testcase_20 AC 90 ms
5,144 KB
testcase_21 AC 87 ms
4,832 KB
testcase_22 AC 97 ms
5,320 KB
testcase_23 AC 101 ms
5,476 KB
testcase_24 WA -
testcase_25 AC 3 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 52 ms
4,376 KB
testcase_28 AC 55 ms
4,616 KB
testcase_29 AC 52 ms
4,376 KB
testcase_30 AC 34 ms
4,376 KB
testcase_31 AC 9 ms
4,376 KB
testcase_32 AC 81 ms
4,952 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 96 ms
5,316 KB
testcase_35 AC 32 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 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;
	for(int i = 0; i < n - 1; i++){
		ll tmp = base;
		tmp -= a[i] % a[(i + 1) % n];
		tmp -= a[n - 1] % a[0];
		tmp += a[n - 1] % a[i];
		tmp += a[i] % a[0];
		ans = max(tmp, ans);
//		cout << tmp << "\n";
	}
	cout << ans;
	return 0;
}
0