Submission #1092368

#TimeUsernameProblemLanguageResultExecution timeMemory
1092368ortsacGroup Photo (JOI21_ho_t3)C++17
0 / 100
0 ms436 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 5005; int dp[MAXN]; int32_t main() { int n; cin >> n; vector<int> v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i]; } dp[0] = 0; for (int k = 1; k <= n; k++) { //cout << "K is " << k << "\n"; dp[k] = INF; vector<int> nv; vector<int> po(k + 1); for (int i = 1; i <= n; i++) { if (v[i] <= k) { po[v[i]] = nv.size(); nv.push_back(v[i]); } } priority_queue<int> neg; int pos = 0; int calc = 0; int t = 0; for (int i = k; i >= 1; i--) { calc = 0; for (int j = i; j <= k; j++) { calc += abs((k - j + i - 1) - po[j]); } dp[k] = min(dp[k], dp[i - 1] + calc); //calc -= ((int)neg.size()); //calc += pos; //calc += abs(po[i] - k + 1); //dp[k] = min(dp[k], dp[i - 1] + calc); //while ((!neg.empty()) && (neg.top() == t)) { // //cout << "removed " << neg.top() << "\n"; // neg.pop(); // pos++; //} //if ((po[i] - k + 1) < 0) { // neg.push(po[i] - k + 1 + t); // //cout << "added from " << i << " it " << po[i] - k + 1 + t << "\n"; //} else pos++; //t--; } //cout << dp[k] << "\n"; } cout << dp[n] << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:29:13: warning: unused variable 'pos' [-Wunused-variable]
   29 |         int pos = 0;
      |             ^~~
Main.cpp:31:13: warning: unused variable 't' [-Wunused-variable]
   31 |         int t = 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...