제출 #989429

#제출 시각아이디문제언어결과실행 시간메모리
989429Tozzyyyy수열 (APIO14_sequence)C++14
0 / 100
12 ms33624 KiB
#include<bits/stdc++.h> #define all(x) (x).begin() , (x).end() #define pll pair<long long, long long> #define fi first #define se second #define bit(i,j) ((j >> i) & 1) using namespace std; #define int long long const long long inf = 1e18+1; const int mod = 998244353; const int MAXN = 10000; int x[MAXN+10] , pre[MAXN + 10]; int dp[MAXN+10] , lst[MAXN+ 10] ;pll trace[MAXN+10][210]; void compute(int l , int r , int optl , int optr , int k){ if(l > r) return; int m = l + r >> 1; pll res = {-1e18 , -1}; for(int i = optl ; i <= min(m , optr) ; i++){ int t = lst[i-1] + ((pre[m] - pre[i-1]) * pre[i-1]); res= max(res , {t , i-1}); } trace[m][k] = {res.se , k-1}; dp[m] = res.fi; int opt = res.se; compute(l , m-1 , optl , opt , k); compute(m + 1 , r , opt, optr , k); } void solve(){ int n , k; cin >> n >> k; for(int i = 1 ; i <= n ; i++){ cin >> x[i]; pre[i] = pre[i-1] + x[i]; } for(int i = 1 ; i <= k; i++){ compute(1 , n , 1 , n , i); for(int i = 0 ; i <= n ; i ++) lst[i] = dp[i] , dp[i] = 0; } cout << lst[n] << "\n"; pll t = {n , k}; vector<int> ans; while(t.fi != 0){ if(trace[t.fi][t.se].fi != 0) cout << trace[t.fi][t.se].fi << " "; t = trace[t.fi][t.se]; } cout << "\n"; } int32_t main(){ //freopen("PAT.INP", "r", stdin); //freopen("PAT.OUT", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }

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

sequence.cpp: In function 'void compute(long long int, long long int, long long int, long long int, long long int)':
sequence.cpp:20:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |  int m = l + r >> 1;
      |          ~~^~~
#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...