제출 #343288

#제출 시각아이디문제언어결과실행 시간메모리
343288mehrdad_sohrabi수열 (APIO14_sequence)C++17
71 / 100
518 ms131076 KiB
#include <bits/stdc++.h> /// 500 485 462 A4 typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair < ll , ll > #define F first #define S second #define endl '\n' #define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout<<x<<'\n', 0; using namespace std; const int N=1e5+100,K=210; ll par[N]; ll a[N]; ll dp[2][N]; ll pd[K][N]; void solve(ll l,ll r,ll L,ll R,ll k){ if (l>r) return ; ll mid=(r+l)/2; ll best=L,val=-1; for (int i=L;i<=min(mid,R);i++){ if (val<(par[mid]-par[i-1])*(par[i-1])+dp[((k+1)&1)][i-1]){ best=i; val=(par[mid]-par[i-1])*(par[i-1])+dp[((k+1)&1)][i-1]; } } //cout << l << " " << r << " " << k << " " << best << " " << val << endl; dp[(k&1)][mid]=val; pd[k][mid]=best-1; solve(l,mid-1,L,best,k); solve(mid+1,r,best,R,k); } ll vis[N]; int32_t main(){ sync; ll n,k; cin >> n >> k; // k++; for (int i=1;i<=n;i++){ cin >> a[i]; par[i]=par[i-1]+a[i]; } for (int i=1;i<=k;i++){ solve(i+1,n,1,n,i); } cout << dp[(k&1)][n] << endl; vector <int> ans; ll x=pd[k][n]; ll zz=k; if (x>0) ans.pb(x); while(k!=1){ // cout << x << " " << k << endl; k--; x=pd[k][x]; if (x<=0) break; ans.pb(x); } for (auto u : ans){ vis[u]=1; } for (int i=1;i<=n;i++){ if (!vis[i] && ans.size()<zz){ ans.pb(i); } } sort(ans.begin(),ans.end()); // reverse(ans.begin(),ans.end()); for (auto u : ans) cout << u << " "; cout << endl; }

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

sequence.cpp: In function 'int32_t main()':
sequence.cpp:67:34: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   67 |         if (!vis[i] && ans.size()<zz){
      |                        ~~~~~~~~~~^~~
#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...