Submission #993893
Source Code Expand
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }
template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
int c=0;
while ( *s!=',' || c!=0 ) {
if ( *s=='(' || *s=='[' || *s=='{' ) c++;
if ( *s==')' || *s==']' || *s=='}' ) c--;
cerr<<*s++;
}
cerr<<"="<<head<<", ";
_dump(s+1,tail...);
}
#define dump(...) do { \
fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
_dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)
template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
s<<"[";
for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
s<<"]";
return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif
template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
_R(head);
R(tail...);
}
template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
if ( i!=x.cbegin() ) putchar(' ');
_W(*i);
}
}
void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
_W(head);
putchar(sizeof...(tail)?' ':'\n');
W(tail...);
}
#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
freopen(name ".in","r",stdin); \
freopen(name ".out","w",stdout); \
} while (0)
#endif
// }}}
const int N=2e5+10;
int n,a[N],m;
LL s[N],dp[N];
map<LL,LL> memo;
int main() {
R(n);
REP1(i,1,n-1) R(a[i]);
REP1(i,1,n) s[i]=s[i-1]+a[i];
R(m);
while ( m-- ) {
R(a[n]);
dp[n-1]=0;
LL mi=s[n-1]-a[n];
vector<LL> v;
for ( int i=n-2; i>=1; i-- ) {
LL h=((LL)i<<40)+mi;
if ( memo.count(h) ) {
dp[1]=memo[h];
break;
}
v.PB(h);
dp[i]=s[i+1]-mi;
// LL now=s[i]+dp[i]-a[i+1];
LL now=2*s[i]-mi;
mi=min(mi,now);
if ( i>1 ) i=lower_bound(s+2,s+i,mi)-s;
}
LL ans=dp[1]+a[1]-a[2];
W(ans);
for ( auto i:v ) memo[i]=dp[1];
}
return 0;
}
Submission Info
Submission Time
2016-11-26 14:21:48+0900
Task
H - Tokaido
User
shik
Language
C++14 (GCC 5.4.1)
Score
1600
Code Size
3640 Byte
Status
AC
Exec Time
727 ms
Memory
56444 KB
Compile Error
./Main.cpp: In function ‘void _R(long long int&)’:
./Main.cpp:62:46: warning: format ‘%ld’ expects argument of type ‘long int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
void _R( long long &x ) { scanf("%" PRId64,&x); }
^
./Main.cpp: In function ‘void _R(int&)’:
./Main.cpp:61:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void _R( int &x ) { scanf("%d",&x); }
^
./Main.cpp: In function ‘void _R(long long int&)’:
./Main.cpp:62:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void _R( long long &x ) { scanf("%" PRId64,&x); }
^
./Main.cpp: In function ‘void _R(double&)’:
./Main.cpp:63:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-resu...
Judge Result
Set Name
sample
dataset1
dataset2
Score / Max Score
0 / 0
700 / 700
900 / 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
19 ms
2560 KB
01-02.txt
AC
3 ms
256 KB
01-03.txt
AC
3 ms
384 KB
01-04.txt
AC
40 ms
7028 KB
01-05.txt
AC
23 ms
3712 KB
01-06.txt
AC
71 ms
12276 KB
01-07.txt
AC
8 ms
1024 KB
01-08.txt
AC
59 ms
10484 KB
01-09.txt
AC
44 ms
7800 KB
01-10.txt
AC
3 ms
256 KB
01-11.txt
AC
6 ms
768 KB
01-12.txt
AC
19 ms
2560 KB
01-13.txt
AC
20 ms
2560 KB
01-14.txt
AC
20 ms
2816 KB
01-15.txt
AC
21 ms
3200 KB
01-16.txt
AC
19 ms
2560 KB
01-17.txt
AC
19 ms
2560 KB
01-18.txt
AC
19 ms
2560 KB
01-19.txt
AC
20 ms
2560 KB
02-01.txt
AC
59 ms
7628 KB
02-02.txt
AC
557 ms
48348 KB
02-03.txt
AC
727 ms
56444 KB
02-04.txt
AC
715 ms
54064 KB
02-05.txt
AC
636 ms
47104 KB
02-06.txt
AC
720 ms
51132 KB
02-07.txt
AC
691 ms
51280 KB
02-08.txt
AC
512 ms
44288 KB
02-09.txt
AC
521 ms
43136 KB
02-10.txt
AC
488 ms
40412 KB
02-11.txt
AC
516 ms
39560 KB
02-12.txt
AC
497 ms
38660 KB
02-13.txt
AC
504 ms
38568 KB
02-14.txt
AC
510 ms
40448 KB
02-15.txt
AC
293 ms
28416 KB
02-16.txt
AC
296 ms
28416 KB
sample-01.txt
AC
3 ms
256 KB
sample-02.txt
AC
3 ms
256 KB