結果

問題 No.2488 Mod Sum Maximization
ユーザー kobaryo222kobaryo222
提出日時 2023-09-29 22:26:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,612 bytes
コンパイル時間 4,695 ms
コンパイル使用メモリ 266,160 KB
実行使用メモリ 15,096 KB
最終ジャッジ日時 2023-09-29 22:26:19
合計ジャッジ時間 7,602 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 23 ms
6,216 KB
testcase_28 AC 25 ms
7,444 KB
testcase_29 AC 23 ms
6,332 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 35 ms
7,068 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
4,376 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pl = pair<ll, ll>;

#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vm vector<mint>
#define vvm vector<vm>
#define vvvm vector<vvm>
#define vp vector<pl>
#define vvp vector<vp>
#define vvvp vector<vvp>
#define vs vector<string>
#define vvs vector<vs>
#define vb vector<bool>
#define vvb vector<vb>
#define vvvb vector<vvb>
#define vd vector<double>
#define vvd vector<vd>
#define vvvd vector<vd>

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) std::begin(x), std::end(x)
#define make_unique(v) v.erase(unique(all(v)), v.end());
#define sum(...) accumulate(all(__VA_ARGS__), 0LL)
#define inf (0x1fffffffffffffffLL)

template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for(auto &x : v) {
        is >> x;
    }
    return is;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int)v.size(); i++) {
        if(i != (int)v.size() - 1)
            os << v[i] << " ";
        else
            os << v[i];
    }
    return os;
}

template <typename T, typename... Args>
auto make_v(T x, int arg, Args... args) {
    if constexpr(sizeof...(args) == 0)
        return vector<T>(arg, x);
    else
        return vector(arg, make_v<T>(x, args...));
}

template <class T>
auto min(const T &a) {
    return *min_element(all(a));
}

template <class T>
auto max(const T &a) {
    return *max_element(all(a));
}

template <class T>
bool chmin(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

template <class T>
bool chmax(T &a, const T &b) {
    return a < b ? a = b, true : false;
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    ll N;
    cin >> N;
    vl A(N);
    cin >> A;
    for(ll i = N - 2; i > 0; i--){
        if(A[A.size() - 1] % A[i] + A[i] % A[0] >= A[i]){
            A.emplace_back(A[i]);
            A[i] = 0;
        }
    }
    vl B;
    rep(i, A.size()) if(A[i] != 0) B.emplace_back(A[i]);
    assert(B.size() == N);
    ll ans = B[N - 1] % B[0];
    rep(i, N - 1) ans += B[i] % B[i + 1];
    cout << ans << endl;
}
0