Submission #1056703

# Submission time Handle Problem Language Result Execution time Memory
1056703 2024-08-13T10:40:22 Z SalihSahin Group Photo (JOI21_ho_t3) C++17
44 / 100
5000 ms 4188 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define double long double
using namespace std;

const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // dp[we put first i elements without changing order of other ones] = minimum cost to get this array
    int n;
    cin>>n;
    vector<int> a(n), dp(n+1, mod);
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    vector<int> arr[n+1];
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= a[i]; j++){
            arr[j].pb(a[i]);
        }
    }

    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        for(int pre = i-1; pre >= 0; pre--){
            // dp[i] = min(dp[i], dp[pre] + cost[i][pre]);
            int cost = 0, ind = 0;
            vector<int> sim = arr[pre + 1];
            for(int j = i; j >= pre + 1; j--){
                int possim = 0;
                for(int pos = 0; pos < sim.size(); pos++){
                    if(sim[pos] == j){
                        possim = pos;
                        break;
                    }
                }
                cost += possim - ind;
                for(int pos = possim; pos >= ind + 1; pos--) sim[pos] = sim[pos - 1];
                sim[ind] = j;
            ind++;
            }

            dp[i] = min(dp[i], dp[pre] + cost);
        }
    }

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

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:34:38: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |                 for(int pos = 0; pos < sim.size(); pos++){
      |                                  ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 87 ms 604 KB Output is correct
22 Correct 70 ms 744 KB Output is correct
23 Correct 70 ms 728 KB Output is correct
24 Correct 76 ms 616 KB Output is correct
25 Correct 79 ms 604 KB Output is correct
26 Correct 75 ms 604 KB Output is correct
27 Correct 75 ms 604 KB Output is correct
28 Correct 75 ms 604 KB Output is correct
29 Correct 75 ms 720 KB Output is correct
30 Correct 75 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 87 ms 604 KB Output is correct
22 Correct 70 ms 744 KB Output is correct
23 Correct 70 ms 728 KB Output is correct
24 Correct 76 ms 616 KB Output is correct
25 Correct 79 ms 604 KB Output is correct
26 Correct 75 ms 604 KB Output is correct
27 Correct 75 ms 604 KB Output is correct
28 Correct 75 ms 604 KB Output is correct
29 Correct 75 ms 720 KB Output is correct
30 Correct 75 ms 732 KB Output is correct
31 Execution timed out 5023 ms 4188 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 87 ms 604 KB Output is correct
22 Correct 70 ms 744 KB Output is correct
23 Correct 70 ms 728 KB Output is correct
24 Correct 76 ms 616 KB Output is correct
25 Correct 79 ms 604 KB Output is correct
26 Correct 75 ms 604 KB Output is correct
27 Correct 75 ms 604 KB Output is correct
28 Correct 75 ms 604 KB Output is correct
29 Correct 75 ms 720 KB Output is correct
30 Correct 75 ms 732 KB Output is correct
31 Execution timed out 5023 ms 4188 KB Time limit exceeded
32 Halted 0 ms 0 KB -