Submission #1092368

# Submission time Handle Problem Language Result Execution time Memory
1092368 2024-09-23T22:58:29 Z ortsac Group Photo (JOI21_ho_t3) C++17
0 / 100
0 ms 436 KB
#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

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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -