Submission #19471161


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,A[404];
int dp[404][404][404];

int hoge(int L,int R,int C) {
	L=max(0,L);
	R=min(N+1,R);
	if(dp[L][R][C]>=0) return dp[L][R][C];
	if(L==0&&R==N+1) return 0;
	
	int ret=0;
	
	if(C) {
		if(L>0) ret=max(ret,A[L]+hoge(L-1,R,C-1));
		if(R<N+1) ret=max(ret,A[R]+hoge(L,R+1,C-1));
	}
	
	
	if(L==0) ret=max(ret,hoge(L,R+1,C+1));
	else if(R==N+1) ret=max(ret,hoge(L-1,R,C+1));
	else {
		if(A[L]>A[R]) {
			ret=max(ret,hoge(L-1,R,C+1));
		}
		else{
			ret=max(ret,hoge(L,R+1,C+1));
		}
	}
	
	return dp[L][R][C]=ret;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	MINUS(dp);
	cin>>N;
	FOR(i,N) cin>>A[i+1];
	
	FOR(i,N+1) {
		cout<<hoge(i,i+1,1)<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task E - Greedy Ant
User kmjp
Language C++ (GCC 9.2.1)
Score 700
Code Size 1528 Byte
Status AC
Exec Time 304 ms
Memory 261204 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:49:8: warning: unused variable ‘j’ [-Wunused-variable]
   49 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:49:10: warning: unused variable ‘k’ [-Wunused-variable]
   49 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:49:12: warning: unused variable ‘l’ [-Wunused-variable]
   49 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:49:14: warning: unused variable ‘r’ [-Wunused-variable]
   49 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:49:16: warning: unused variable ‘x’ [-Wunused-variable]
   49 |  int i,j,k,l,r,x,y; string s;
      |                ^
./Main.cpp:49:18: warning: unused variable ‘y’ [-Wunused-variable]
   49 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:65:38: note: in expansion of macro ‘FOR’
   65 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 52
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, random_45.txt, random_46.txt, random_47.txt, random_48.txt, random_49.txt, random_50.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
random_01.txt AC 304 ms 261120 KB
random_02.txt AC 298 ms 261204 KB
random_03.txt AC 301 ms 261180 KB
random_04.txt AC 300 ms 261112 KB
random_05.txt AC 303 ms 261060 KB
random_06.txt AC 303 ms 261052 KB
random_07.txt AC 300 ms 261204 KB
random_08.txt AC 299 ms 261064 KB
random_09.txt AC 302 ms 261116 KB
random_10.txt AC 300 ms 261116 KB
random_11.txt AC 174 ms 261120 KB
random_12.txt AC 266 ms 261000 KB
random_13.txt AC 185 ms 261116 KB
random_14.txt AC 161 ms 261172 KB
random_15.txt AC 207 ms 261168 KB
random_16.txt AC 264 ms 261188 KB
random_17.txt AC 168 ms 261116 KB
random_18.txt AC 158 ms 261112 KB
random_19.txt AC 163 ms 261092 KB
random_20.txt AC 264 ms 261176 KB
random_21.txt AC 163 ms 261044 KB
random_22.txt AC 229 ms 261116 KB
random_23.txt AC 163 ms 261040 KB
random_24.txt AC 262 ms 261048 KB
random_25.txt AC 188 ms 261180 KB
random_26.txt AC 229 ms 261108 KB
random_27.txt AC 175 ms 261124 KB
random_28.txt AC 265 ms 261052 KB
random_29.txt AC 165 ms 260980 KB
random_30.txt AC 226 ms 261172 KB
random_31.txt AC 174 ms 261100 KB
random_32.txt AC 160 ms 261176 KB
random_33.txt AC 234 ms 261124 KB
random_34.txt AC 165 ms 261172 KB
random_35.txt AC 208 ms 260992 KB
random_36.txt AC 157 ms 261112 KB
random_37.txt AC 241 ms 261040 KB
random_38.txt AC 164 ms 261024 KB
random_39.txt AC 206 ms 261188 KB
random_40.txt AC 169 ms 261112 KB
random_41.txt AC 237 ms 261116 KB
random_42.txt AC 157 ms 261088 KB
random_43.txt AC 210 ms 261172 KB
random_44.txt AC 171 ms 261128 KB
random_45.txt AC 236 ms 261128 KB
random_46.txt AC 163 ms 261036 KB
random_47.txt AC 211 ms 261180 KB
random_48.txt AC 262 ms 261176 KB
random_49.txt AC 187 ms 261168 KB
random_50.txt AC 159 ms 260976 KB
sample_01.txt AC 159 ms 261024 KB
sample_02.txt AC 162 ms 261144 KB