結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー fastmathfastmath
提出日時 2020-08-12 19:31:32
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,214 bytes
コンパイル時間 2,564 ms
コンパイル使用メモリ 165,560 KB
実行使用メモリ 8,520 KB
最終ジャッジ日時 2024-04-18 00:49:33
合計ジャッジ時間 4,762 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 15 ms
5,848 KB
testcase_23 AC 15 ms
6,352 KB
testcase_24 AC 16 ms
7,216 KB
testcase_25 AC 14 ms
6,396 KB
testcase_26 AC 16 ms
5,884 KB
testcase_27 AC 16 ms
6,560 KB
testcase_28 AC 19 ms
8,520 KB
testcase_29 AC 14 ms
5,984 KB
testcase_30 AC 15 ms
6,052 KB
testcase_31 AC 15 ms
6,292 KB
testcase_32 AC 17 ms
7,472 KB
testcase_33 AC 16 ms
6,232 KB
testcase_34 AC 15 ms
6,216 KB
testcase_35 AC 17 ms
6,668 KB
testcase_36 AC 19 ms
7,988 KB
testcase_37 AC 17 ms
6,748 KB
testcase_38 AC 15 ms
5,972 KB
testcase_39 AC 15 ms
6,372 KB
testcase_40 AC 17 ms
7,696 KB
testcase_41 AC 17 ms
6,156 KB
testcase_42 AC 14 ms
6,276 KB
testcase_43 AC 14 ms
6,660 KB
testcase_44 AC 18 ms
6,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
int solve(vector <int> l, vector <int> r) {

    auto half = [] (vector <int> a) {
        int sz = a.size();
        int ans = 0;
        for (int i = 0; i < sz/2; ++i) {
            ans += a[i];
            ans -= a[sz - 1 - i];
        }        
        return ans;                        
    };  

    auto mid = [] (vector <int> a) {
        int sz = a.size();
        assert(sz&1);
        return a[sz/2];
    };  

    if (l.size() % 2 == 0 && r.size() % 2 == 0) {
        return half(l) + half(r);
    }   
    else if (l.size() % 2 && r.size() % 2 == 0) {
        return half(l) + half(r) + mid(l);
    }   
    else if (l.size() % 2 == 0 && r.size() % 2) {
        return half(l) + half(r) + mid(r);
    }   
    else {
        assert(0);
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    int s, t;
    cin >> s >> t;
    s--; t--;
    vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    
    vector <int> l, r;
    for (int i = min(s, t) + 1; i != max(s, t); i++) {
        l.app(a[i]);
    }   
    if (s > t)
        reverse(all(l));
    for (int i = (max(s, t) + 1) % n; i != min(s, t); i = (i + 1) % n) {
        r.app(a[i]);
    }   
    if (s < t)
        reverse(all(r));

    auto shift = [] (vector <int> a) {
        vector <int> ans;
        for (int i = 1; i < a.size(); ++i)
            ans.app(a[i]);
        return ans;
    };  
    auto rev = [] (vector <int> a) {
        reverse(all(a));
        return a;
    };
    if (l.size() % 2 && r.size() % 2) {
        cout << max(l[0] - solve(rev(shift(l)), rev(r)), r[0] - solve(rev(l), rev(shift(r)))) + a[s] - a[t] << endl;
    }    
    else {
        cout << solve(l, r) + a[s] - a[t] << endl;
    }   
}
0