제출 #1066460

#제출 시각아이디문제언어결과실행 시간메모리
1066460beaconmc수열 (APIO14_sequence)C++14
0 / 100
35 ms39928 KiB
#include <vector> #include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; ll dp[10001][201]; ll prevs[1001][201]; deque<vector<ll>> sus; bool sussy(ll a, ll b, ll mi, ll ci){ return (sus[a][1] - ci) * (sus[a][0] - sus[b][0]) < (mi, - sus[a][0]) * (sus[b][1] - sus[a][1]); } int main(){ ll n,k; cin >> n >> k; vector<ll> arr(n); vector<ll> pref(n); FOR(i,0,n) cin >> arr[i]; pref[0] = arr[0]; FOR(i,1,n) pref[i] = pref[i-1]+arr[i]; FOR(i,0,10001)FOR(j,0,201) dp[i][j] = -1000000000; dp[0][0] = 0; FOR(j,1,k+1){ sus.clear(); sus.push_back({-pref[0]+arr[0], dp[0][j-1], 0}); FOR(i,1,n+1){ ll temp = (pref[n-1] - pref[i-1]); while (sus.size() >= 2 && (temp * sus[1][0] + sus[1][1]) > (temp * sus[0][0] + sus[0][1])){ sus.pop_front(); } ll ans = temp * sus[0][0] + sus[0][1] + (pref[n-1] - pref[i-1]) * pref[i-1]; if (dp[i][j] < ans){ dp[i][j] = ans; prevs[i][j] = sus[0][2]; } ll newtemp = (pref[n-1] - pref[i]); while (sus.size()>=2 && sussy(sus.size()-2, sus.size()-1, (-pref[i]+arr[i]), dp[i][j-1])) { sus.pop_back(); } sus.push_back({(-pref[i]+arr[i]), dp[i][j-1], i}); } } ll maxi = -1; ll pos = -1; FORNEG(i,n-1,-1) if (dp[i][k] > maxi) maxi = dp[i][k], pos = i; cout << dp[pos][k] << endl; FOR(i,0,k){ ll sus = prevs[pos][k-i]; cout << pos << " "; pos = sus; } }

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

sequence.cpp: In function 'bool sussy(ll, ll, ll, ll)':
sequence.cpp:17:55: warning: left operand of comma operator has no effect [-Wunused-value]
   17 |  return (sus[a][1] - ci) * (sus[a][0] - sus[b][0]) < (mi, - sus[a][0]) * (sus[b][1] - sus[a][1]);
      |                                                       ^~
sequence.cpp: In function 'int main()':
sequence.cpp:58:7: warning: unused variable 'newtemp' [-Wunused-variable]
   58 |    ll newtemp = (pref[n-1] - 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...