Submission #3664562
Source Code Expand
//https://beta.atcoder.jp/contests/code-thanks-festival-2018-open/tasks/code_thanks_festival_2018_h #include<bits/stdc++.h> using namespace std; typedef long long LL; #ifdef BTK #define DEBUG if(1) #else #define CIN_ONLY if(1) struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star; #define DEBUG if(0) #endif #define ALL(v) (v).begin(),(v).end() #define REC(ret, ...) std::function<ret (__VA_ARGS__)> template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;} template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;} template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;} class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }}; int N; LL a[1123]; LL as[1123]; bool vis[2][1123]; LL dp[2][1123]; LL threshold; inline LL sum(int i,int j){ return as[j]-as[i]; } inline LL cost(int i,int j){ return sum(i,j)>=threshold?1:-1; } void g(int turn,int k){ if(vis[turn][k])return; vis[turn][k]=true; if(k==N){ dp[turn][k]=0; return; } if(turn==0){ LL &ret=dp[turn][k]; ret=-1e15; for(int l:range(k+1,N+1)){ g(1-turn,l); chmax(ret,cost(k,l)+dp[1-turn][l]); } } else{ LL &ret=dp[turn][k]; ret=1e15; for(int l:range(k+1,N+1)){ g(1-turn,l); chmin(ret,cost(k,l)+dp[1-turn][l]); } } } bool f(){ for(int i:range(2))for(int j:range(1123))vis[i][j]=false; g(0,0); return dp[0][0]>=0; } int main(){ cin>>N; for(int i:range(N)){ cin>>a[i]; as[i+1]=as[i]+a[i]; } LL ng=1e13; LL ok=-1e13; while(ng-ok>1){ //cout<<ng<<" "<<ok<<endl; threshold=(ok+ng)/2; if(f())ok=threshold; else ng=threshold; } cout<<ok<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | H - Median Game |
User | btk15049 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 2199 Byte |
Status | AC |
Exec Time | 175 ms |
Memory | 384 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 1 ms | 256 KB |
02.txt | AC | 1 ms | 256 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 1 ms | 256 KB |
06.txt | AC | 1 ms | 256 KB |
07.txt | AC | 1 ms | 256 KB |
08.txt | AC | 1 ms | 256 KB |
09.txt | AC | 1 ms | 256 KB |
10.txt | AC | 1 ms | 256 KB |
11.txt | AC | 173 ms | 384 KB |
12.txt | AC | 163 ms | 384 KB |
13.txt | AC | 144 ms | 384 KB |
14.txt | AC | 163 ms | 384 KB |
15.txt | AC | 150 ms | 384 KB |
16.txt | AC | 164 ms | 384 KB |
17.txt | AC | 170 ms | 384 KB |
18.txt | AC | 157 ms | 384 KB |
19.txt | AC | 165 ms | 384 KB |
20.txt | AC | 165 ms | 384 KB |
21.txt | AC | 158 ms | 384 KB |
22.txt | AC | 163 ms | 384 KB |
23.txt | AC | 161 ms | 384 KB |
24.txt | AC | 160 ms | 384 KB |
25.txt | AC | 168 ms | 384 KB |
26.txt | AC | 160 ms | 384 KB |
27.txt | AC | 158 ms | 384 KB |
28.txt | AC | 175 ms | 384 KB |
29.txt | AC | 160 ms | 384 KB |
30.txt | AC | 167 ms | 384 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |