Submission #1277166

#TimeUsernameProblemLanguageResultExecution timeMemory
1277166ducdevSolar Storm (NOI20_solarstorm)C++17
70 / 100
2094 ms27828 KiB
// Author: 4uckd3v - Nguyen Cao Duc #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 1e6; const int MOD = 1e9 + 7; const ll INF = 1e18; int n, s; int d[MAX_N + 5], v[MAX_N + 5]; ll k; ll pref[MAX_N + 5]; ll getSum(int l, int r) { if (l > r) return 0; return pref[r] - (l == 0 ? 0 : pref[l - 1]); }; namespace SUBTASK_12356 { const int LIM = 1e8; const int N = MAX_N; int L[N + 5], R[N + 5], nextPos[N + 5]; void Solve() { ll dist = 0; for (int i = 1; i <= n; i++) { L[i] = max(1, L[i - 1]); while (L[i] < i && dist > k) { dist -= d[L[i]]; L[i]++; }; dist += d[i]; }; dist = 0; R[n] = n; for (int i = n - 1; i >= 1; i--) { dist += d[i]; R[i] = R[i + 1]; while (R[i] > i && dist > k) { dist -= d[R[i] - 1]; R[i]--; }; }; for (int i = 1; i <= n; i++) { nextPos[i] = max(i, nextPos[i - 1]); while (nextPos[i] < n && L[nextPos[i] + 1] <= R[i] + 1) nextPos[i]++; if (nextPos[i] <= i) nextPos[i] = -1; }; ll res = 0; int traceIdx = 0, traceCnt = 0; for (int i = 1; i <= n; i++) { ll sum = 0; int cnt = 0, curPos = i; while (true) { cnt++; if (nextPos[curPos] == -1 || cnt == s) { sum += getSum(L[curPos], R[curPos]); break; }; sum += getSum(L[curPos], L[nextPos[curPos]] - 1); curPos = nextPos[curPos]; }; if (res < sum) { res = sum; traceIdx = i; traceCnt = cnt; }; }; cout << traceCnt << '\n'; while (true) { traceCnt--; cout << traceIdx << ' '; if (nextPos[traceIdx] == -1 || traceCnt == 0) break; traceIdx = nextPos[traceIdx]; }; }; }; // namespace SUBTASK_12356 namespace SUBTASK_4 { const int N = MAX_N; bool checkSubtask() { for (int i = 1; i < n; i++) if (d[i] != 2) return false; return k == 1; }; void Solve() { ll sum = 0, res = 0; int l = 0, r = 0; for (int i = 1; i <= n; i++) { sum += v[i]; if (i > s) sum -= v[i - s]; if (res < sum) { res = sum; l = max(1, i - s + 1); r = i; }; }; cout << r - l + 1 << '\n'; for (int i = l; i <= r; i++) cout << i << ' '; }; }; // namespace SUBTASK_4 int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("MAIN.INP", "r")) { freopen("MAIN.INP", "r", stdin); freopen("MAIN.OUT", "w", stdout); }; cin >> n >> s >> k; for (int i = 1; i < n; i++) { cin >> d[i]; }; for (int i = 1; i <= n; i++) { cin >> v[i]; pref[i] = pref[i - 1] + v[i]; }; if (SUBTASK_4::checkSubtask()) return SUBTASK_4::Solve(), 0; SUBTASK_12356::Solve(); };

Compilation message (stderr)

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