Submission #637614

# Submission time Handle Problem Language Result Execution time Memory
637614 2022-09-02T13:14:04 Z danikoynov Group Photo (JOI21_ho_t3) C++14
0 / 100
0 ms 212 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 5010;

int n, a[maxn], dp[maxn], pos[maxn], cnt[maxn][maxn];
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        pos[a[i]] = i;
    }

    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++)

    {
        cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1];
        if (pos[i] == j)
            cnt[i][j] ++;
    }

    for (int i = 1; i <= n; i ++, cout << endl)
        for (int j = 1; j <= n; j ++)
        cout << cnt[i][j] << " ";
    for (int i = 1; i <= n; i ++)
    {
        dp[i] = n * n;
        for (int j = 0; j < i; j ++)
        {
            int st = j + 1, sum = 0;
            for (int k = i; k > j; k --)
            {
                ///ll cur = pos[k] + (j + (i - k) - query(pos[k] - 1));
                ll cur = pos[k] + j - cnt[j][pos[k]] + (i - k) - (cnt[i][pos[k]] - cnt[k][pos[k]]);
                ///cout << i << " : " << j << " : " << k << " " << cur << " " << cnt[i][pos[k]] << endl;
                cur -= st;
                st ++;
                sum = sum + max((ll)0, cur);
            }

            ///cout << i << " " << j << " " << sum << endl;
            dp[i] = min(dp[i], dp[j] + sum);
        }

        ///cout << i << " -- " << dp[i] << endl;

    }
    cout << dp[n] << endl;

}

int main()
{
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -