답안 #378904

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378904 2021-03-17T07:20:24 Z Atill83 Group Photo (JOI21_ho_t3) C++14
100 / 100
425 ms 134508 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 5e3+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
int a[MAXN];
int dp[MAXN];
int s[MAXN];

int arr[MAXN][MAXN], brr[MAXN][MAXN];


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif



    cin>>n;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    for(int i = 1; i <= n; i++){
        dp[i] = mod;
        for(int j = a[i]; j <= n; j++)
            s[j]++;

        for(int j = a[i]; j <= n; j++){
            arr[a[i]][j] = s[n] - s[j];
            brr[a[i]][j] = (j - a[i]) - (s[j] - s[a[i]]);
        }
    }

    for(int i = 1; i <= n; i++){
        int sum = 0;
    
        for(int j = i; j >= 1; j--){
            sum += arr[j][i] + brr[j][i];
            dp[i] = min(dp[i], dp[j - 1] + sum);
        }
    }

    cout<<dp[n]<<endl;


    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 2 ms 2156 KB Output is correct
22 Correct 2 ms 2156 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 2 ms 2156 KB Output is correct
25 Correct 2 ms 2156 KB Output is correct
26 Correct 2 ms 2284 KB Output is correct
27 Correct 2 ms 2156 KB Output is correct
28 Correct 2 ms 2156 KB Output is correct
29 Correct 2 ms 2156 KB Output is correct
30 Correct 2 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 2 ms 2156 KB Output is correct
22 Correct 2 ms 2156 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 2 ms 2156 KB Output is correct
25 Correct 2 ms 2156 KB Output is correct
26 Correct 2 ms 2284 KB Output is correct
27 Correct 2 ms 2156 KB Output is correct
28 Correct 2 ms 2156 KB Output is correct
29 Correct 2 ms 2156 KB Output is correct
30 Correct 2 ms 2156 KB Output is correct
31 Correct 9 ms 9324 KB Output is correct
32 Correct 9 ms 9324 KB Output is correct
33 Correct 9 ms 9324 KB Output is correct
34 Correct 10 ms 9324 KB Output is correct
35 Correct 9 ms 9324 KB Output is correct
36 Correct 9 ms 9324 KB Output is correct
37 Correct 9 ms 9324 KB Output is correct
38 Correct 9 ms 9324 KB Output is correct
39 Correct 9 ms 9324 KB Output is correct
40 Correct 9 ms 9324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 2 ms 2156 KB Output is correct
22 Correct 2 ms 2156 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 2 ms 2156 KB Output is correct
25 Correct 2 ms 2156 KB Output is correct
26 Correct 2 ms 2284 KB Output is correct
27 Correct 2 ms 2156 KB Output is correct
28 Correct 2 ms 2156 KB Output is correct
29 Correct 2 ms 2156 KB Output is correct
30 Correct 2 ms 2156 KB Output is correct
31 Correct 9 ms 9324 KB Output is correct
32 Correct 9 ms 9324 KB Output is correct
33 Correct 9 ms 9324 KB Output is correct
34 Correct 10 ms 9324 KB Output is correct
35 Correct 9 ms 9324 KB Output is correct
36 Correct 9 ms 9324 KB Output is correct
37 Correct 9 ms 9324 KB Output is correct
38 Correct 9 ms 9324 KB Output is correct
39 Correct 9 ms 9324 KB Output is correct
40 Correct 9 ms 9324 KB Output is correct
41 Correct 403 ms 134424 KB Output is correct
42 Correct 405 ms 134252 KB Output is correct
43 Correct 405 ms 134380 KB Output is correct
44 Correct 396 ms 134508 KB Output is correct
45 Correct 401 ms 134400 KB Output is correct
46 Correct 399 ms 134380 KB Output is correct
47 Correct 407 ms 134440 KB Output is correct
48 Correct 414 ms 134380 KB Output is correct
49 Correct 400 ms 134400 KB Output is correct
50 Correct 403 ms 134380 KB Output is correct
51 Correct 397 ms 134440 KB Output is correct
52 Correct 395 ms 134380 KB Output is correct
53 Correct 425 ms 134380 KB Output is correct
54 Correct 397 ms 134380 KB Output is correct
55 Correct 402 ms 134508 KB Output is correct