답안 #637629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637629 2022-09-02T13:29:24 Z danikoynov Group Photo (JOI21_ho_t3) C++14
64 / 100
5000 ms 98316 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 sum = 0;
            for (int k = i; k > j; k --)
            {
                ///ll cur = pos[k] + (j + (i - k) - query(pos[k] - 1));
                ll cur = (cnt[n][pos[k]] - cnt[i][pos[k]]) + (cnt[k - 1][pos[k]] - cnt[j][pos[k]]);

                ///cout << i << " : " << j << " : " << k << " " << cnt[n][pos[k]] << " " << cnt[k][pos[k]] << endl;
                //cur -= st;
                //st ++;
                sum = sum + 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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 3 ms 1236 KB Output is correct
23 Correct 4 ms 1236 KB Output is correct
24 Correct 3 ms 1236 KB Output is correct
25 Correct 4 ms 1236 KB Output is correct
26 Correct 4 ms 1236 KB Output is correct
27 Correct 5 ms 1236 KB Output is correct
28 Correct 3 ms 1236 KB Output is correct
29 Correct 5 ms 1236 KB Output is correct
30 Correct 3 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 3 ms 1236 KB Output is correct
23 Correct 4 ms 1236 KB Output is correct
24 Correct 3 ms 1236 KB Output is correct
25 Correct 4 ms 1236 KB Output is correct
26 Correct 4 ms 1236 KB Output is correct
27 Correct 5 ms 1236 KB Output is correct
28 Correct 3 ms 1236 KB Output is correct
29 Correct 5 ms 1236 KB Output is correct
30 Correct 3 ms 1236 KB Output is correct
31 Correct 173 ms 6012 KB Output is correct
32 Correct 168 ms 6036 KB Output is correct
33 Correct 188 ms 6036 KB Output is correct
34 Correct 181 ms 5972 KB Output is correct
35 Correct 164 ms 5972 KB Output is correct
36 Correct 168 ms 6036 KB Output is correct
37 Correct 200 ms 6036 KB Output is correct
38 Correct 165 ms 6028 KB Output is correct
39 Correct 160 ms 6044 KB Output is correct
40 Correct 157 ms 6048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 3 ms 1236 KB Output is correct
23 Correct 4 ms 1236 KB Output is correct
24 Correct 3 ms 1236 KB Output is correct
25 Correct 4 ms 1236 KB Output is correct
26 Correct 4 ms 1236 KB Output is correct
27 Correct 5 ms 1236 KB Output is correct
28 Correct 3 ms 1236 KB Output is correct
29 Correct 5 ms 1236 KB Output is correct
30 Correct 3 ms 1236 KB Output is correct
31 Correct 173 ms 6012 KB Output is correct
32 Correct 168 ms 6036 KB Output is correct
33 Correct 188 ms 6036 KB Output is correct
34 Correct 181 ms 5972 KB Output is correct
35 Correct 164 ms 5972 KB Output is correct
36 Correct 168 ms 6036 KB Output is correct
37 Correct 200 ms 6036 KB Output is correct
38 Correct 165 ms 6028 KB Output is correct
39 Correct 160 ms 6044 KB Output is correct
40 Correct 157 ms 6048 KB Output is correct
41 Execution timed out 5084 ms 98316 KB Time limit exceeded
42 Halted 0 ms 0 KB -