제출 #1284074

#제출 시각아이디문제언어결과실행 시간메모리
1284074cheskaSolar Storm (NOI20_solarstorm)C++20
0 / 100
272 ms327680 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define ppii pair<int, pii> #define tiii tuple<int, int, int> #define g0 get<0> #define g1 get<1> #define g2 get<2> #define f first #define pb push_back const int N = 1e6+5; const int S = 50; const int MOD = 1e9+7; signed main() { freopen("in.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); int n, s, k; cin >> n >> s >> k; vector<int> a(n); for (int i = 1; i < n; i++) { int j; cin >> j; a[i]=a[i-1]+j; } vector<int> v(n), psv(n); for (int i = 0; i < n; i++) cin >> v[i]; psv[0] = v[0]; for (int i = 1; i < n; i++) { psv[i] = psv[i-1]+v[i]; } vector<vector<int>> ans(n, vector<int>(2)); vector<int> r(n), l(n); for (int i = 0; i < n; i++) { r[i] = upper_bound(a.begin(), a.end(), a[i]+k)-a.begin(); l[i] = lower_bound(a.begin(), a.end(), a[i]-k)-a.begin(); } for (int j = 1; j <= s; j++) { for (int i = n-1; i >= 0; i--) { if (r[i] == n) { if (l[i] == 0) ans[i][j%2] = psv[n-1]; else ans[i][j%2] = psv[n-1]-psv[l[i]-1]; } else { if (l[i] == 0) ans[i][j%2] = ans[r[i]][(j+1)%2]; else ans[i][j%2] = ans[r[i]][(j+1)%2]+psv[r[i]-1]-psv[l[i]-1]; } } } int ans2 = 0; for (int i = 0; i < n; i++) { if (ans[ans2][s%2] < ans[i][s%2]) ans2 = i; } int s2 = s; vector<int> fin; while (ans2 != n && s >= 0) { fin.pb(ans2); ans2 = r[ans2]; s--; } int x = fin.size(); cout << min(x, s2) << '\n'; for (int i = 0; i < min(x, s2); i++) { cout << fin[i]+1 << " "; } }

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

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen("in.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...