Submission #583483

# Submission time Handle Problem Language Result Execution time Memory
583483 2022-06-25T12:07:44 Z AngusWong Group Photo (JOI21_ho_t3) C++17
44 / 100
5000 ms 320 KB
#include <bits/stdc++.h>
using namespace std;

int n, a[5001], p, pos[5001], t, dp[5001], bit[5001];
vector<int> v;

void upd(int x){
    for (int i=x; i<=n; i+=(i&(-i))) bit[i]++;
}

int qry(int x){
    int ans=0;
    for (int i=x; i; i-=(i&(-i))) ans+=bit[i];
    return ans;
}

int main() {
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++){
        dp[i]=2e9;
        for (int j=1; j<=i; j++){
            p=1;
            v.clear();
            v.push_back(-1);
            for (int k=1; k<=n; k++) bit[k]=0;
            for (int k=i; k>=j; k--) pos[k]=p++;
            for (int k=1; k<=n; k++){
                if (a[k]>i) pos[a[k]]=p++;
                if (a[k]>=j) v.push_back(a[k]);
            }
            t=0;
            for (int k=1; k<v.size(); k++){
                t+=qry(n)-qry(pos[v[k]]);
                upd(pos[v[k]]);
            }
            dp[i]=min(dp[i], dp[j-1]+t);
        }
    }
    cout << dp[n] << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int k=1; k<v.size(); k++){
      |                           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 69 ms 308 KB Output is correct
22 Correct 67 ms 304 KB Output is correct
23 Correct 71 ms 212 KB Output is correct
24 Correct 70 ms 304 KB Output is correct
25 Correct 69 ms 304 KB Output is correct
26 Correct 70 ms 300 KB Output is correct
27 Correct 65 ms 212 KB Output is correct
28 Correct 63 ms 212 KB Output is correct
29 Correct 65 ms 304 KB Output is correct
30 Correct 70 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 69 ms 308 KB Output is correct
22 Correct 67 ms 304 KB Output is correct
23 Correct 71 ms 212 KB Output is correct
24 Correct 70 ms 304 KB Output is correct
25 Correct 69 ms 304 KB Output is correct
26 Correct 70 ms 300 KB Output is correct
27 Correct 65 ms 212 KB Output is correct
28 Correct 63 ms 212 KB Output is correct
29 Correct 65 ms 304 KB Output is correct
30 Correct 70 ms 304 KB Output is correct
31 Correct 4899 ms 320 KB Output is correct
32 Execution timed out 5012 ms 308 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 69 ms 308 KB Output is correct
22 Correct 67 ms 304 KB Output is correct
23 Correct 71 ms 212 KB Output is correct
24 Correct 70 ms 304 KB Output is correct
25 Correct 69 ms 304 KB Output is correct
26 Correct 70 ms 300 KB Output is correct
27 Correct 65 ms 212 KB Output is correct
28 Correct 63 ms 212 KB Output is correct
29 Correct 65 ms 304 KB Output is correct
30 Correct 70 ms 304 KB Output is correct
31 Correct 4899 ms 320 KB Output is correct
32 Execution timed out 5012 ms 308 KB Time limit exceeded
33 Halted 0 ms 0 KB -