제출 #566345

#제출 시각아이디문제언어결과실행 시간메모리
566345XEMPLI5수열 (APIO14_sequence)C++17
0 / 100
16 ms1236 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> trees(n), pref(n); for (int i = 0; i < n; i++) { cin >> trees[i]; pref[i] = trees[i]; if (i) pref[i] += pref[i - 1]; } set<pair<int, int>> parts; parts.insert({0, n - 1}); int ans = 0; vector<int> moves; for (int l = 0; l < k; l++) { int mxVal = 0, loc = -1, mst = -1, med = -1; for (auto e : parts) { int st = e.first, ed = e.second; int curVal = 0; for (int i = st; i < ed; i++) { int fpart = pref[i]; if (st) fpart -= pref[st - 1]; int spart = pref[ed]; spart -= pref[i]; int curVal = spart * fpart; if (curVal >= mxVal) { mxVal = curVal; loc = i; mst = st; med = ed; } } } if (loc != -1) { ans += mxVal; moves.push_back(loc + 1); parts.erase(parts.find({mst, med})); parts.insert({mst, loc}); parts.insert({loc + 1, med}); } else break; } cout << ans << '\n'; for (auto e : moves) { cout << e << ' '; } return 0; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:32:17: warning: unused variable 'curVal' [-Wunused-variable]
   32 |             int curVal = 0;
      |                 ^~~~~~
#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...