Submission #18997858
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;
int A[504];
int dp[505][505];
int hoge(int L,int R) {
if(L>=R) return 0;
if(dp[L][R]>-1<<30) return dp[L][R];
int ret=0;
for(int M=L+1;M<R;M++) ret=max(ret,hoge(L,M)+hoge(M,R));
for(int M=L+1;M<R-1;M++) {
if((M-L-1)%3==0&&((R-1)-M-1)%3==0) {
ret=max(ret,A[L]+A[M]+A[R-1]+hoge(L+1,M)+hoge(M+1,R-1));
}
}
return dp[L][R]=ret;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
FOR(x,N+1) FOR(y,N+1) dp[x][y]=-1<<30;
cout<<hoge(0,N)<<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 |
B - Three Coins |
User |
kmjp |
Language |
C++ (GCC 9.2.1) |
Score |
800 |
Code Size |
1350 Byte |
Status |
AC |
Exec Time |
154 ms |
Memory |
4700 KB |
Compile Error
./Main.cpp: In function ‘int hoge(int, int)’:
./Main.cpp:22:18: warning: left shift of negative value [-Wshift-negative-value]
22 | if(dp[L][R]>-1<<30) return dp[L][R];
| ^~
./Main.cpp: In function ‘void solve()’:
./Main.cpp:40:37: warning: left shift of negative value [-Wshift-negative-value]
40 | FOR(x,N+1) FOR(y,N+1) dp[x][y]=-1<<30;
| ^~
./Main.cpp:36:8: warning: unused variable ‘j’ [-Wunused-variable]
36 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp:36:10: warning: unused variable ‘k’ [-Wunused-variable]
36 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp:36:12: warning: unused variable ‘l’ [-Wunused-variable]
36 | int i,j,k,l,r,x,y; string s;
| ^
./Main.cpp:36:14: warning: unused variable ‘r’ [-Wunused-variable]
36 | 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:49:38: note: in expansion of macro ‘FOR’
49 | 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 |
800 / 800 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt, example2.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, example0.txt, example1.txt, example2.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
AC |
152 ms |
4612 KB |
001.txt |
AC |
150 ms |
4616 KB |
002.txt |
AC |
149 ms |
4624 KB |
003.txt |
AC |
153 ms |
4700 KB |
004.txt |
AC |
147 ms |
4608 KB |
005.txt |
AC |
151 ms |
4684 KB |
006.txt |
AC |
150 ms |
4612 KB |
007.txt |
AC |
148 ms |
4656 KB |
008.txt |
AC |
152 ms |
4648 KB |
009.txt |
AC |
153 ms |
4656 KB |
010.txt |
AC |
148 ms |
4616 KB |
011.txt |
AC |
152 ms |
4492 KB |
012.txt |
AC |
153 ms |
4696 KB |
013.txt |
AC |
151 ms |
4604 KB |
014.txt |
AC |
152 ms |
4532 KB |
015.txt |
AC |
150 ms |
4604 KB |
016.txt |
AC |
151 ms |
4536 KB |
017.txt |
AC |
154 ms |
4552 KB |
018.txt |
AC |
149 ms |
4604 KB |
019.txt |
AC |
150 ms |
4552 KB |
020.txt |
AC |
150 ms |
4640 KB |
021.txt |
AC |
152 ms |
4592 KB |
022.txt |
AC |
149 ms |
4544 KB |
023.txt |
AC |
148 ms |
4608 KB |
024.txt |
AC |
152 ms |
4640 KB |
025.txt |
AC |
148 ms |
4592 KB |
026.txt |
AC |
151 ms |
4608 KB |
027.txt |
AC |
152 ms |
4536 KB |
028.txt |
AC |
148 ms |
4624 KB |
029.txt |
AC |
151 ms |
4496 KB |
030.txt |
AC |
151 ms |
4608 KB |
031.txt |
AC |
151 ms |
4492 KB |
032.txt |
AC |
152 ms |
4656 KB |
033.txt |
AC |
150 ms |
4692 KB |
034.txt |
AC |
152 ms |
4648 KB |
035.txt |
AC |
148 ms |
4692 KB |
036.txt |
AC |
151 ms |
4624 KB |
037.txt |
AC |
153 ms |
4680 KB |
038.txt |
AC |
149 ms |
4604 KB |
039.txt |
AC |
151 ms |
4588 KB |
040.txt |
AC |
150 ms |
4652 KB |
041.txt |
AC |
148 ms |
4680 KB |
042.txt |
AC |
150 ms |
4680 KB |
043.txt |
AC |
152 ms |
4696 KB |
044.txt |
AC |
152 ms |
4588 KB |
045.txt |
AC |
153 ms |
4648 KB |
example0.txt |
AC |
4 ms |
3508 KB |
example1.txt |
AC |
2 ms |
3624 KB |
example2.txt |
AC |
2 ms |
3600 KB |