結果

問題 No.2488 Mod Sum Maximization
ユーザー 沙耶花沙耶花
提出日時 2023-09-29 22:16:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 4,972 ms
コンパイル使用メモリ 262,760 KB
実行使用メモリ 5,560 KB
最終ジャッジ日時 2023-09-29 22:16:55
合計ジャッジ時間 9,252 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 107 ms
5,308 KB
testcase_05 WA -
testcase_06 AC 101 ms
5,252 KB
testcase_07 WA -
testcase_08 AC 104 ms
5,560 KB
testcase_09 AC 80 ms
5,180 KB
testcase_10 WA -
testcase_11 AC 4 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 65 ms
4,476 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 87 ms
4,892 KB
testcase_20 AC 95 ms
5,120 KB
testcase_21 AC 91 ms
4,876 KB
testcase_22 AC 103 ms
5,284 KB
testcase_23 AC 106 ms
5,420 KB
testcase_24 WA -
testcase_25 AC 4 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 56 ms
4,376 KB
testcase_28 AC 57 ms
4,452 KB
testcase_29 AC 54 ms
4,376 KB
testcase_30 AC 36 ms
4,380 KB
testcase_31 AC 8 ms
4,380 KB
testcase_32 AC 87 ms
4,908 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 104 ms
5,296 KB
testcase_35 AC 34 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

int main(){
	
	int n;
	cin>>n;
	vector<long long> a(n);
	rep(i,n){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	long long ans = 0;
	rep(i,n-1)ans += a[i];
	ans += a[n-1]%a[0];
	
	vector<long long> dp(3,-Inf64);
	dp[0] = 0;
	for(int i=1;i<n-1;i++){
		vector<long long> ndp = dp;//(3,-Inf64);
		{
			ndp[1] = max(ndp[1],dp[0] - a.back()%a[0] + a.back()%a[i]);
		}
		{
			ndp[2] = max(ndp[2],dp[1] - a[i] + a[i]%a[0]);
		}
		{
			ndp[2] = max(ndp[2],dp[0] - a[i] + a[i]%a[0] - a.back()%a[0] + a.back()%a[i]);
		}
		swap(dp,ndp);
	}
	ans += max({dp[0],dp[2]});
	cout<<ans<<endl;
	return 0;
}
0