Submission #994099
Source Code Expand
#include<bits/stdc++.h> using namespace std; typedef long long ll; int N,M; ll A[200005]; ll dp[200005][2][2]; const ll INF = 10000000000000000LL; ll solve(int id,int pl,int fr){ if( dp[id][pl][fr] != -1 ) return dp[id][pl][fr]; if( id == N ) return dp[id][pl][fr] = 0; ll ret = 0; if( pl ) ret = -INF; //1:snuke else ret = INF; //0:rng if( fr ){//front ll st = solve(id+1,1-pl,0); if( pl ) ret = max( ret, st + A[id+1] ); else ret = min( ret, st - A[id+1] ); if( id < N-1 ) { st = solve(id+1,pl,1); if( pl ) ret = max( ret, st - A[id+1] ); else ret = min( ret, st + A[id+1] ); } } else { //usual ll st = solve(id+1,1-pl,0); if( pl ) ret = max( ret, st ) + A[id+1]; else ret = min( ret, st ) - A[id+1]; if( id < N-1 ){ st = solve(id+1,pl,1); if( pl ) ret = max( ret, st - A[id+1] ); else ret = min( ret, st + A[id+1] ); } } // cout << id << " " << pl << " "<< fr << " = " << ret << endl; return dp[id][pl][fr] = ret; } int main(){ cin >> N; for(int i=0;i<N-1;i++) cin >> A[i]; cin >> M; if( M > 2 ) return 0; for(int i=0;i<M;i++){ int x; cin >> x; A[N] = x; memset( dp,-1,sizeof( dp ) ) ; cout << solve( 1, 1, 0 ) + A[0]-A[1] << endl; } }
Submission Info
Submission Time | |
---|---|
Task | H - Tokaido |
User | sate3saku3 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1332 Byte |
Status | WA |
Exec Time | 70 ms |
Memory | 20608 KB |
Judge Result
Set Name | sample | dataset1 | dataset2 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | 0 / 900 | ||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
dataset1 | sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt |
dataset2 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 63 ms | 20608 KB |
01-02.txt | AC | 8 ms | 6528 KB |
01-03.txt | AC | 9 ms | 6656 KB |
01-04.txt | AC | 39 ms | 13184 KB |
01-05.txt | AC | 67 ms | 20608 KB |
01-06.txt | AC | 66 ms | 20608 KB |
01-07.txt | AC | 27 ms | 10496 KB |
01-08.txt | AC | 70 ms | 20480 KB |
01-09.txt | AC | 69 ms | 20608 KB |
01-10.txt | AC | 9 ms | 6528 KB |
01-11.txt | AC | 19 ms | 9216 KB |
01-12.txt | AC | 63 ms | 19968 KB |
01-13.txt | AC | 65 ms | 20608 KB |
01-14.txt | AC | 65 ms | 20352 KB |
01-15.txt | AC | 64 ms | 20608 KB |
01-16.txt | AC | 63 ms | 20608 KB |
01-17.txt | AC | 63 ms | 20608 KB |
01-18.txt | AC | 63 ms | 20608 KB |
01-19.txt | AC | 63 ms | 20608 KB |
02-01.txt | WA | 10 ms | 512 KB |
02-02.txt | WA | 38 ms | 1792 KB |
02-03.txt | WA | 40 ms | 1792 KB |
02-04.txt | WA | 36 ms | 1792 KB |
02-05.txt | WA | 3 ms | 256 KB |
02-06.txt | WA | 39 ms | 1792 KB |
02-07.txt | WA | 36 ms | 1792 KB |
02-08.txt | WA | 3 ms | 256 KB |
02-09.txt | WA | 3 ms | 256 KB |
02-10.txt | WA | 20 ms | 1024 KB |
02-11.txt | WA | 37 ms | 1792 KB |
02-12.txt | WA | 37 ms | 1792 KB |
02-13.txt | WA | 38 ms | 1792 KB |
02-14.txt | WA | 35 ms | 1792 KB |
02-15.txt | WA | 36 ms | 1792 KB |
02-16.txt | WA | 35 ms | 1792 KB |
sample-01.txt | AC | 9 ms | 6528 KB |
sample-02.txt | WA | 3 ms | 256 KB |