結果

問題 No.2488 Mod Sum Maximization
ユーザー ococonomy1ococonomy1
提出日時 2023-09-29 22:06:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,653 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 113,388 KB
実行使用メモリ 5,488 KB
最終ジャッジ日時 2023-09-29 22:07:00
合計ジャッジ時間 4,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 38 ms
5,116 KB
testcase_07 WA -
testcase_08 AC 40 ms
5,360 KB
testcase_09 AC 30 ms
4,960 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 32 ms
4,944 KB
testcase_20 WA -
testcase_21 AC 34 ms
5,156 KB
testcase_22 WA -
testcase_23 AC 41 ms
5,356 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 20 ms
4,380 KB
testcase_28 AC 21 ms
4,380 KB
testcase_29 AC 20 ms
4,380 KB
testcase_30 AC 15 ms
4,380 KB
testcase_31 WA -
testcase_32 AC 32 ms
4,912 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 37 ms
5,088 KB
testcase_35 AC 13 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using lg = long long;
using pii = pair<int, int>;
using pll = pair<lg, lg>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
//#define AMARI 1000000007
#define TEMOTO ((sizeof(long double) == 16) ? false : true)
#define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000)
#define el '\n'
#define El '\n'

// 疑似乱数(XorShift)
unsigned long xor128(void) {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


#define MULTI_TEST_CASE false
void solve(void) {
    int n;
    cin >> n;
    lg ans = 0;
    vector<lg> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i != n -1)ans += a[i];
    }
    ans += a.back() % a[0];
    for(int i = 1; i < n - 1; i++){
        lg temp = ans;
        temp -= a[i - 1] % a[i];
        temp -= a[i] % a[i + 1];
        temp -= a[n - 1] % a[0];

        temp += a[i - 1] % a[i + 1];
        temp += a[n - 1] % a[i];
        temp += a[i] % a[0];
        ans = max(ans,temp);
    }
    cout << ans << el;
    return;
}

void calc(void) {
    int n = 5;
    vector<int> a(n);
    
    for(int i = 0; i < n; i++){
        if(i == 0)a[i] = xor128() % 2 + 1;
        else{
            a[i] = a[i - 1] + xor128() % 10 + 1;
        }
    }
    
    cout << "a = {";
    for(int i = 0; i < n; i++){
        if(i)cout << ',';
        cout << a[i];
    }
    cout << "}\n";
    lg ans = 0;
    vector<int> tempv;
    int cnt = 0;
    do{
        lg temp = 0;
        for(int i = 0; i < n - 1; i++){
            temp += a[i] % a[i + 1];
        }
        temp += a.back() % a[0];
        if(temp > ans){
            ans = temp;
            tempv = a;
            cnt = 1;
        }
        if(temp == ans)cnt++;
    }while(next_permutation(a.begin(),a.end()));
    cout << ans << el;
    cout << cnt << el;
    for(int i = 0; i < n; i++)cout << tempv[i] << ' ';
    cout << el;
    cout << el;

    return;
}

int main(void) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    /*
    
    for(int i = 0; i < 100; i++){
        calc();
    }
    */
    int t = 1;
    if(MULTI_TEST_CASE) cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
0