Submission #134942

# Submission time Handle Problem Language Result Execution time Memory
134942 2019-07-23T13:03:46 Z CaroLinda Split the sequence (APIO14_sequence) C++14
11 / 100
3 ms 504 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 int inf = 0x3f3f3f3f ;
const int MAXN = 12 ;

using namespace std ;

int n , k ;
ll dp[ (1<<MAXN) ] , pref[MAXN]  , ans = 0 ;

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

bool isOn(int m, int bit) { return ( (m&(1<<bit)) != 0 ) ; }

int countBits(int m)
{
	int tot = 0 ;

	lp(i,1,n+1)
		if( isOn(m,i) ) tot ++ ;

	return tot ;
}

int findDir(int m,int bit)
{

	lp(i,bit+1,n+1)
		if(isOn(m,i)) return i ;

	return n ;
}

int findEsq(int m, int bit)
{

	for(int i = bit-1 ; i > 0 ; i-- )
		if( isOn(m, i) ) return i ;

	return 0 ;
}

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 m = 0 ; m < (1<<(n+1)) ; m ++ )
	{
		if( countBits(m) >= k || isOn(m,0)) continue ;

		lp(i,1,n+1)
			if( !isOn(m,i) )
			{
				int esq = findEsq( m , i ) ;
				int dir = findDir( m , i ) ;

				ll ganho = get(esq+1, i)*get(i+1,dir) ;

				dp[ (m|(1<<i) ) ] = max(dp[ (m|(1<<i) ) ] , dp[m] + ganho ) ;

			}


	}

	lp(m,0,(1<<(n+1)))
		if( countBits(m) == k && !isOn(m,0) )
			ans = max(ans, dp[m]) ;

	printf("%lld\n" , ans ) ;

	lp(m,0,(1<<(n+1))-1 )
		if( countBits(m) == k && !isOn(m,0) && dp[m] == ans )
		{
			lp(i,1,n+1)
				if(isOn(m,i)) printf("%d " , i ) ;
			break ;
		}
	printf("\n") ;

}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:53: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:54: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] ) ;
              ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 376 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 256 KB contestant found the optimal answer: 0 == 0
4 Correct 2 ms 376 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 2 ms 376 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 2 ms 376 KB contestant found the optimal answer: 1 == 1
7 Correct 2 ms 376 KB contestant found the optimal answer: 1 == 1
8 Correct 2 ms 256 KB contestant found the optimal answer: 1 == 1
9 Correct 2 ms 376 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 2 ms 376 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 2 ms 376 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 2 ms 376 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 2 ms 376 KB contestant found the optimal answer: 140072 == 140072
14 Correct 2 ms 376 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 2 ms 376 KB contestant found the optimal answer: 805 == 805
16 Correct 2 ms 376 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 2 ms 376 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -