Submission #134942

#TimeUsernameProblemLanguageResultExecution timeMemory
134942CaroLindaSplit the sequence (APIO14_sequence)C++14
11 / 100
3 ms504 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...