結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー outlineoutline
提出日時 2020-12-20 19:24:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,274 bytes
コンパイル時間 1,416 ms
コンパイル使用メモリ 136,852 KB
実行使用メモリ 5,024 KB
最終ジャッジ日時 2023-10-21 10:58:56
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 13 ms
4,632 KB
testcase_23 AC 13 ms
4,672 KB
testcase_24 AC 12 ms
4,672 KB
testcase_25 AC 12 ms
4,592 KB
testcase_26 AC 14 ms
4,928 KB
testcase_27 AC 13 ms
4,952 KB
testcase_28 AC 14 ms
4,796 KB
testcase_29 AC 12 ms
4,756 KB
testcase_30 AC 14 ms
4,716 KB
testcase_31 AC 13 ms
4,644 KB
testcase_32 AC 13 ms
4,632 KB
testcase_33 AC 14 ms
4,736 KB
testcase_34 AC 15 ms
4,744 KB
testcase_35 AC 15 ms
4,936 KB
testcase_36 AC 16 ms
4,944 KB
testcase_37 AC 16 ms
5,008 KB
testcase_38 AC 12 ms
4,652 KB
testcase_39 AC 13 ms
4,624 KB
testcase_40 AC 13 ms
4,688 KB
testcase_41 AC 14 ms
4,764 KB
testcase_42 AC 12 ms
5,024 KB
testcase_43 AC 12 ms
5,024 KB
testcase_44 AC 15 ms
4,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, s, t;
    cin >> N >> s >> t;
    --s, --t;
    vector<int> A(N);
    for(int i = 0; i < N; ++i)  cin >> A[i];

    ll ans = A[s] - A[t];
    vector<int> B, C;
    int i = (s - 1 + N) % N;
    while(i != t){
        B.emplace_back(A[i]);
        i = (i - 1 + N) % N;
    }
    i = (s + 1) % N;
    while(i != t){
        C.emplace_back(A[i]);
        i = (i + 1) % N;
    }
    int n = B.size(), m = C.size();
    vector<ll> SB(n + 1), SC(m + 1);
    for(int i = 0; i < n; ++i)  SB[i + 1] = SB[i] + B[i];
    for(int i = 0; i < m; ++i)  SC[i + 1] = SC[i] + C[i];
    if(n % 2 == 0 && m % 2 == 0){
        ans += SB[n / 2] + SC[m / 2];
        ans -= SB[n] - SB[n / 2] + SC[m] - SC[m / 2];
    }
    else if(n % 2 == 0){
        ans += SB[n / 2] + SC[(m + 1) / 2];
        ans -= SB[n] - SB[n / 2] + SC[m] - SC[(m + 1) / 2];
    }
    else if(m % 2 == 0){
        ans += SB[(n + 1) / 2] + SC[m / 2];
        ans -= SB[n] - SB[(n + 1) / 2] + SC[m] - SC[m / 2];
    }
    else{
        ll sum = 0, sum2 = 0;
        sum += SB[(n + 1) / 2] + SC[m / 2];
        sum -= SB[n] - SB[(n + 1) / 2] + SC[m] - SC[m / 2];
        sum2 += SB[n / 2] + SC[(m + 1) / 2];
        sum2 -= SB[n] - SB[n / 2] + SC[m] - SC[(m + 1) / 2];
        ans += max(sum, sum2);
    }

    cout << ans << endl;

    return 0;
}
0