Submission #413006

# Submission time Handle Problem Language Result Execution time Memory
413006 2021-05-28T02:27:29 Z Ozy Group Photo (JOI21_ho_t3) C++17
44 / 100
5000 ms 332 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl
#define debugarr(x,a,b) cout << #x << " = ["; rep(iii, a, b) cout << x[iii] << ", "; cout << "]\n"

#define MAX 5000
#define INF (1 << 30)

lli n;
lli arr[MAX+2],dp[MAX+2];

lli costo(lli ini, lli fin){
    vector<lli> nuevo;
    lli cnt, res, pos, t;

    res = 0;
    rep(i, 1, n){
        if (arr[i] >= ini && arr[i] <= fin){
            nuevo.push_back(arr[i]);
            --cnt;
            if (!cnt) break;
        }
        else if (arr[i] > fin) nuevo.push_back(arr[i]);
    }

    t = 0;
    repa(i, fin, ini){
        rep(j, t, nuevo.size() - 1) if (nuevo[j] == i){
            pos = j;
            break;
        }
        repa(j, pos, t + 1){
            swap(nuevo[j], nuevo[j - 1]);
            ++res;
        }
        ++t;
    }
    return res;
}

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

    cin >>n;
    rep(i,1,n) {
        cin >> arr[i];
    }

    dp[0] = 0;
    rep(i,1,n) {
        dp[i] = INF;
        rep(j,0,i-1) {
            dp[i] = min(dp[i], dp[j] + costo(j + 1, i));
        }
    }

    cout << dp[n];

    return 0;
}

Compilation message

Main.cpp: In function 'long long int costo(long long int, long long int)':
Main.cpp:4:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(i,a,b) for (int i = (a); i <= (b); i++)
      |                                        ^
Main.cpp:33:9: note: in expansion of macro 'rep'
   33 |         rep(j, t, nuevo.size() - 1) if (nuevo[j] == i){
      |         ^~~
Main.cpp:37:14: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |         repa(j, pos, t + 1){
      |              ^
Main.cpp:25:13: warning: 'cnt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |             --cnt;
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 157 ms 320 KB Output is correct
22 Correct 160 ms 308 KB Output is correct
23 Correct 153 ms 320 KB Output is correct
24 Correct 167 ms 316 KB Output is correct
25 Correct 163 ms 204 KB Output is correct
26 Correct 163 ms 204 KB Output is correct
27 Correct 161 ms 308 KB Output is correct
28 Correct 173 ms 308 KB Output is correct
29 Correct 160 ms 312 KB Output is correct
30 Correct 162 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 157 ms 320 KB Output is correct
22 Correct 160 ms 308 KB Output is correct
23 Correct 153 ms 320 KB Output is correct
24 Correct 167 ms 316 KB Output is correct
25 Correct 163 ms 204 KB Output is correct
26 Correct 163 ms 204 KB Output is correct
27 Correct 161 ms 308 KB Output is correct
28 Correct 173 ms 308 KB Output is correct
29 Correct 160 ms 312 KB Output is correct
30 Correct 162 ms 324 KB Output is correct
31 Execution timed out 5051 ms 332 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 157 ms 320 KB Output is correct
22 Correct 160 ms 308 KB Output is correct
23 Correct 153 ms 320 KB Output is correct
24 Correct 167 ms 316 KB Output is correct
25 Correct 163 ms 204 KB Output is correct
26 Correct 163 ms 204 KB Output is correct
27 Correct 161 ms 308 KB Output is correct
28 Correct 173 ms 308 KB Output is correct
29 Correct 160 ms 312 KB Output is correct
30 Correct 162 ms 324 KB Output is correct
31 Execution timed out 5051 ms 332 KB Time limit exceeded
32 Halted 0 ms 0 KB -