Submission #1036475

# Submission time Handle Problem Language Result Execution time Memory
1036475 2024-07-27T12:19:02 Z aymanrs Giraffes (JOI22_giraffes) C++17
59 / 100
469 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n;cin >> n;
    int p[n];for(int i = 0;i < n;i++) {
        cin >> p[i];
        p[i]--;
    }
    int dp[n+1][n+1][n+1];
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= n;j++) dp[i][n-i][j] = 0;
    }
    for(int su = n-1;su >= 0;su--){
        for(int i = 0;i <= su;i++){
            int j = su-i;
            int vj = n-j-1;
            for(int k = 0;k < n;k++){
                dp[i][j][k] = min({
                    dp[i+1][j][k+1] + (p[k] != i),
                    dp[i+1][j][k] + (p[k+(n-i-j)-1] != i),
                    dp[i][j+1][k+1] + (p[k] != vj),
                    dp[i][j+1][k] + (p[k+(n-i-j)-1] != vj)
                });
            }
        }
    }
    cout << dp[0][0][0] << '\n';
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 3932 KB Output is correct
23 Correct 20 ms 25436 KB Output is correct
24 Correct 43 ms 56592 KB Output is correct
25 Correct 70 ms 95824 KB Output is correct
26 Correct 83 ms 102740 KB Output is correct
27 Correct 76 ms 103760 KB Output is correct
28 Correct 77 ms 105044 KB Output is correct
29 Correct 75 ms 106068 KB Output is correct
30 Correct 102 ms 106944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 3 ms 3932 KB Output is correct
23 Correct 20 ms 25436 KB Output is correct
24 Correct 43 ms 56592 KB Output is correct
25 Correct 70 ms 95824 KB Output is correct
26 Correct 83 ms 102740 KB Output is correct
27 Correct 76 ms 103760 KB Output is correct
28 Correct 77 ms 105044 KB Output is correct
29 Correct 75 ms 106068 KB Output is correct
30 Correct 102 ms 106944 KB Output is correct
31 Runtime error 469 ms 1048576 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -