답안 #135098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135098 2019-07-23T16:02:34 Z CaroLinda 수열 (APIO14_sequence) C++14
39 / 100
163 ms 2936 KB
#include <bits/stdc++.h>

#define lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair

const ll inf = 1e15 ;
const int MAXN = 1010 ;
const int MAXK = 210 ;

using namespace std ;

int n , k ;
ll pref[MAXN] , dp[MAXN][MAXK] ;
int cut[MAXN][MAXK] ;
vector<int> ans ;

ll get(int i , int j) { return pref[j] - pref[i-1] ; }

void buildAns(int ini, int c)
{
	if(c==0) return ;
	ans.pb( cut[ini][c] ) ;
	buildAns(cut[ini][c]+1,c-1) ;
}

int main()
{

	scanf("%d%d", &n , &k ) ;
	lp(i,1,n+1) scanf("%lld", &pref[i] ) ;
	
	lp(i,1,n+1) pref[i] += pref[i-1] ;	

	for(int c = 1 ; c <= k ; c++)
	{
		for(int i = n ; i > 0 ; i-- )
		{
			if( n - i < c ) { dp[i][c] = -inf ; continue ; }

			for(int j = i ; j < n ; j++ )
			{
				ll ganho = dp[j+1][c-1] + get(i,j)*get(j+1,n) ;
				if(ganho > dp[i][c])
					cut[i][c] = j , dp[i][c] = ganho ;
			}
		}
	}

	buildAns(1,k) ;

	printf("%lld\n" , dp[1][k]);

	lp(i,0,k) printf("%d ", ans[i]) ;
	printf("\n");
	
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n , &k ) ;
  ~~~~~^~~~~~~~~~~~~~~~~~
sequence.cpp:35:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  lp(i,1,n+1) scanf("%lld", &pref[i] ) ;
              ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 376 KB contestant found the optimal answer: 999 == 999
3 Incorrect 2 ms 376 KB Integer 0 violates the range [1, 1]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 2 ms 376 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 2 ms 376 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 2 ms 504 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 2 ms 504 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 2 ms 376 KB contestant found the optimal answer: 933702 == 933702
7 Correct 2 ms 504 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 2 ms 504 KB contestant found the optimal answer: 687136 == 687136
9 Correct 2 ms 504 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 2 ms 504 KB contestant found the optimal answer: 29000419931 == 29000419931
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 888 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 3 ms 888 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 6 ms 864 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 3 ms 888 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 6 ms 888 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 7 ms 760 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 6 ms 760 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 4 ms 760 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 3 ms 892 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 4 ms 888 KB contestant found the optimal answer: 490686959791 == 490686959791
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2780 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 7 ms 2808 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 157 ms 2848 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 7 ms 2936 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 163 ms 2908 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 141 ms 2936 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 161 ms 2808 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 158 ms 2808 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 38 ms 2808 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 69 ms 2808 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Integer 0 violates the range [1, 9999]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -