제출 #677369

#제출 시각아이디문제언어결과실행 시간메모리
677369penguin133Solar Storm (NOI20_solarstorm)C++17
36 / 100
258 ms78784 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif int n, s, k, A[1000005], B[1000005], P[1000005], X[1000005], dp[1000005]; pi pre[1000005]; pi p[1000005]; void solve(){ cin >> n >> s >> k; for(int i=2;i<=n;i++)cin >> A[i], P[i] = P[i-1] + A[i]; for(int i=1;i<=n;i++)cin >> B[i], X[i] = X[i-1] + B[i]; for(int i=1;i<=n;i++){ int lo = 1, hi = i, ans = hi; while(lo <= hi){ int mid = (lo + hi) >> 1; if(P[i] - P[mid] <= k)ans = mid, hi = mid - 1; else lo = mid + 1; } lo = 1, hi = ans; int ans2 = ans; while(lo <= hi){ int mid = (lo + hi) >> 1; if(P[ans] - P[mid] <= k)ans2 = mid, hi = mid - 1; else lo = mid + 1; } pre[i] = {ans2 - 1, ans}; } int bt = 1, rem = s - 1; while(rem && bt <= n){ rem--; int lo = bt, hi = n, ans = lo; while(lo <= hi){ int mid = (lo + hi) >> 1; if(P[mid] - P[bt] <= k)ans = mid, lo = mid + 1; else hi = mid - 1; } lo = ans, hi = n; int ans2 = ans; while(lo <= hi){ int mid = (lo + hi) >> 1; if(P[mid] - P[ans] <= k)ans2 = mid, lo = mid + 1; else hi = mid - 1; } bt = ans2 + 1; } //cerr << bt << " "; vector<int> fin; int mx = 0, in = 0; for(int i=1;i<bt;i++){ dp[i] = X[i]; p[i] = {1, 0}; if(dp[i] > mx)mx = dp[i], in = i; } p[0] = {1, 0}; for(int i=bt;i<=n;i++){ pi tmp = pre[i]; //cout << pre[i].fi << " " << p[tmp.fi].fi << " " << p[tmp.fi].se << '\n'; if(mx < dp[tmp.fi] - (X[p[tmp.fi].se] - X[p[tmp.fi].fi - 1]) + X[i] - X[tmp.fi])mx = dp[tmp.fi] - (X[p[tmp.fi].se] - X[p[tmp.fi].fi - 1]) + X[i] - X[tmp.fi], in = i; dp[i] = dp[tmp.fi] - (X[p[tmp.fi].se] - X[p[tmp.fi].fi - 1]) + X[i] - X[tmp.fi]; int lo = p[tmp.fi].se + 1, hi = i, ans = lo; while(lo <= hi){ int mid = (lo + hi) >> 1; if(P[mid] - P[p[tmp.fi].se + 1] <= k)ans = mid, lo = mid + 1; else hi = mid - 1; } lo = ans, hi = i; int ans2 = ans; while(lo <= hi){ int mid = (lo + hi) >> 1; if(P[mid] - P[ans] <= k)ans2 = mid, lo = mid + 1; else hi = mid - 1; } //cout << dp[i] << " " << p[i].fi << " " << p[i].se << '\n'; p[i] = {p[tmp.fi].se + 1, ans2}; } bt = in, rem = s; vector<int> v; while(rem && bt){ rem--; v.push_back(pre[bt].se); bt = pre[bt].fi; } //cout << mx << '\n'; cout << (int)v.size() << '\n'; for(auto i : v)cout << i << " "; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

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

SolarStorm.cpp:97:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   97 | main(){
      | ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...