Submission #575409


Source Code Expand

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream &operator << (ostream &os, const vector<T> &);
template<size_t n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, const tuple<T...> &){}
template<size_t n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream &os, const tuple<T...> &t){
    os << (n == 0 ? "" : " ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T> ostream &operator << (ostream &os, const tuple<T...> &t){
    _ot<0>(os, t); return os;
}
template<class T, class U> ostream & operator << (ostream &os, const pair<T,U> &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T> ostream &operator << (ostream &os, const vector<T> &v){
    for(size_t i = 0; i < v.size(); i++) os << v[i] << (i + 1 == v.size() ? "" : ", "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << make_tuple(__VA_ARGS__) \
                   << " (L : " << __LINE__ << ")" << endl)
#else
#define dump(...)
#endif
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using ll = long long;
// #define int ll
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
void fastios(){ ios_base::sync_with_stdio(0); cin.tie(0); }
int const mod = 1000000007;
auto const inf = numeric_limits<int>::max()/8;

int n;
vi a;

pair<int,int> calc(vi x){
    int t = 0, a = 0;
    rep(j,x.size()){
        if(j%2 == 0) t += x[j]; else a += x[j];
    }
    return mp(t,a);
}

vi solve(int k){
    int res = -inf;
    vi res_v;
    rep(i,n){
        if(i == k) continue;
        vi rem;
        rep(j,n) if((i <= j && j <= k) || (k <= j && j <= i)) rem.pb(a[j]);
        int a = calc(rem).second;
        if(res < a){
            res = a;
            res_v = rem;
        }
    }
    return res_v;
}

int solve(){
    int ans = -inf;
    rep(i,n){
        vi rem = solve(i);
        int t = calc(rem).first;
        ans = max(ans, t);
    }
    return ans;
}

int main(){
    while(cin >> n){
        a.resize(n);
        rep(i,n) cin >> a[i];
        cout << solve() << endl;
    }
}

Submission Info

Submission Time
Task C - 数列ゲーム
User tubo28
Language C++11 (GCC 4.9.2)
Score 100
Code Size 2387 Byte
Status AC
Exec Time 37 ms
Memory 928 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 20
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt
Case Name Status Exec Time Memory
sample-01.txt AC 27 ms 912 KB
sample-02.txt AC 26 ms 792 KB
sample-03.txt AC 25 ms 928 KB
test-01.txt AC 27 ms 804 KB
test-02.txt AC 27 ms 800 KB
test-03.txt AC 27 ms 676 KB
test-04.txt AC 26 ms 800 KB
test-05.txt AC 27 ms 732 KB
test-06.txt AC 28 ms 732 KB
test-07.txt AC 28 ms 808 KB
test-08.txt AC 28 ms 920 KB
test-09.txt AC 27 ms 928 KB
test-10.txt AC 26 ms 796 KB
test-11.txt AC 26 ms 792 KB
test-12.txt AC 26 ms 912 KB
test-13.txt AC 26 ms 784 KB
test-14.txt AC 37 ms 800 KB
test-15.txt AC 27 ms 804 KB
test-16.txt AC 29 ms 796 KB
test-17.txt AC 28 ms 800 KB
test-18.txt AC 32 ms 804 KB
test-19.txt AC 30 ms 812 KB
test-20.txt AC 31 ms 800 KB