Submission #3664895
Source Code Expand
#include <iostream> #include <string> #include <vector> #include <array> #include <algorithm> using namespace std; using ll = long long; static const ll INF = 1000000000000000ll; static int dp[1001][2]; int main(){ ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; ++i){ cin >> a[i]; } ll lo = -INF, hi = INF; while(lo < hi){ const ll mid = lo + (hi - lo) / 2; vector<array<int, 2>> dp(n + 1, {0, 0}); for(int i = n - 1; i >= 0; --i){ ll sum = 0; int alice = -n, bob = n; for(int j = i + 1; j <= n; ++j){ sum += a[j - 1]; if(sum >= mid){ alice = max(alice, dp[j][1] + 1); bob = min(bob, dp[j][0] + 1); }else{ alice = max(alice, dp[j][1] - 1); bob = min(bob, dp[j][0] - 1); } } dp[i][0] = alice; dp[i][1] = bob; } if(dp[0][0] >= 0){ lo = mid + 1; }else{ hi = mid; } } cout << lo - 1 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | H - Median Game |
User | logicmachine |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 986 Byte |
Status | AC |
Exec Time | 45 ms |
Memory | 256 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 | 42 ms | 256 KB |
12.txt | AC | 40 ms | 256 KB |
13.txt | AC | 36 ms | 256 KB |
14.txt | AC | 40 ms | 256 KB |
15.txt | AC | 38 ms | 256 KB |
16.txt | AC | 40 ms | 256 KB |
17.txt | AC | 42 ms | 256 KB |
18.txt | AC | 39 ms | 256 KB |
19.txt | AC | 41 ms | 256 KB |
20.txt | AC | 41 ms | 256 KB |
21.txt | AC | 40 ms | 256 KB |
22.txt | AC | 41 ms | 256 KB |
23.txt | AC | 42 ms | 256 KB |
24.txt | AC | 39 ms | 256 KB |
25.txt | AC | 42 ms | 256 KB |
26.txt | AC | 42 ms | 256 KB |
27.txt | AC | 42 ms | 256 KB |
28.txt | AC | 45 ms | 256 KB |
29.txt | AC | 41 ms | 256 KB |
30.txt | AC | 43 ms | 256 KB |
s1.txt | AC | 1 ms | 256 KB |
s2.txt | AC | 1 ms | 256 KB |