제출 #135098

#제출 시각아이디문제언어결과실행 시간메모리
135098CaroLinda수열 (APIO14_sequence)C++14
39 / 100
163 ms2936 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 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"); }

컴파일 시 표준 에러 (stderr) 메시지

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] ) ;
              ~~~~~^~~~~~~~~~~~~~~~~~~
#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...