# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
408882 | 2021-05-19T18:48:43 Z | mat_v | Group Photo (JOI21_ho_t3) | C++14 | 857 ms | 294596 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n; int niz[5005]; int dp[5005]; int ans[5005]; int poz[5005]; int pref[5005][5005]; int suff1[5005][5005]; int suff2[5005][5005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; ff(i,1,n){ cin >> niz[i]; poz[niz[i]] = i; } ff(i,1,n){ ff(j,0,n){ if(niz[i] > j)pref[i][j]++; pref[i][j] += pref[i - 1][j]; } } fb(i,n,1){ ff(j,0,n){ if(niz[i] >= j)suff1[i][j]++; suff1[i][j] += suff1[i + 1][j]; if(niz[i] <= j)suff2[i][j]++; suff2[i][j] += suff2[i + 1][j]; } } dp[n] = 0; fb(i,n-1,0){ ans[0] = 0; dp[i] = 1e9; ff(j,i+1,n){ ans[j-i] = ans[j-i-1]; ans[j-i] += pref[poz[j] - 1][i]; if(j != i+1){ int ost = n - poz[j]; ost -= suff1[poz[j]+1][j]; ost -= suff2[poz[j]+1][i]; ans[j-i] -= ost; } dp[i] = min(dp[i], ans[j-i] + dp[j]); } } cout << dp[0] << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 324 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 460 KB | Output is correct |
8 | Correct | 1 ms | 460 KB | Output is correct |
9 | Correct | 2 ms | 460 KB | Output is correct |
10 | Correct | 1 ms | 460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 324 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 460 KB | Output is correct |
8 | Correct | 1 ms | 460 KB | Output is correct |
9 | Correct | 2 ms | 460 KB | Output is correct |
10 | Correct | 1 ms | 460 KB | Output is correct |
11 | Correct | 1 ms | 460 KB | Output is correct |
12 | Correct | 1 ms | 460 KB | Output is correct |
13 | Correct | 1 ms | 460 KB | Output is correct |
14 | Correct | 1 ms | 588 KB | Output is correct |
15 | Correct | 1 ms | 588 KB | Output is correct |
16 | Correct | 1 ms | 588 KB | Output is correct |
17 | Correct | 1 ms | 588 KB | Output is correct |
18 | Correct | 1 ms | 588 KB | Output is correct |
19 | Correct | 1 ms | 588 KB | Output is correct |
20 | Correct | 1 ms | 588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 324 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 460 KB | Output is correct |
8 | Correct | 1 ms | 460 KB | Output is correct |
9 | Correct | 2 ms | 460 KB | Output is correct |
10 | Correct | 1 ms | 460 KB | Output is correct |
11 | Correct | 1 ms | 460 KB | Output is correct |
12 | Correct | 1 ms | 460 KB | Output is correct |
13 | Correct | 1 ms | 460 KB | Output is correct |
14 | Correct | 1 ms | 588 KB | Output is correct |
15 | Correct | 1 ms | 588 KB | Output is correct |
16 | Correct | 1 ms | 588 KB | Output is correct |
17 | Correct | 1 ms | 588 KB | Output is correct |
18 | Correct | 1 ms | 588 KB | Output is correct |
19 | Correct | 1 ms | 588 KB | Output is correct |
20 | Correct | 1 ms | 588 KB | Output is correct |
21 | Correct | 3 ms | 3148 KB | Output is correct |
22 | Correct | 3 ms | 3148 KB | Output is correct |
23 | Correct | 3 ms | 3144 KB | Output is correct |
24 | Correct | 3 ms | 3136 KB | Output is correct |
25 | Correct | 3 ms | 3148 KB | Output is correct |
26 | Correct | 3 ms | 3140 KB | Output is correct |
27 | Correct | 3 ms | 3148 KB | Output is correct |
28 | Correct | 3 ms | 3148 KB | Output is correct |
29 | Correct | 3 ms | 3148 KB | Output is correct |
30 | Correct | 3 ms | 3148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 324 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 460 KB | Output is correct |
8 | Correct | 1 ms | 460 KB | Output is correct |
9 | Correct | 2 ms | 460 KB | Output is correct |
10 | Correct | 1 ms | 460 KB | Output is correct |
11 | Correct | 1 ms | 460 KB | Output is correct |
12 | Correct | 1 ms | 460 KB | Output is correct |
13 | Correct | 1 ms | 460 KB | Output is correct |
14 | Correct | 1 ms | 588 KB | Output is correct |
15 | Correct | 1 ms | 588 KB | Output is correct |
16 | Correct | 1 ms | 588 KB | Output is correct |
17 | Correct | 1 ms | 588 KB | Output is correct |
18 | Correct | 1 ms | 588 KB | Output is correct |
19 | Correct | 1 ms | 588 KB | Output is correct |
20 | Correct | 1 ms | 588 KB | Output is correct |
21 | Correct | 3 ms | 3148 KB | Output is correct |
22 | Correct | 3 ms | 3148 KB | Output is correct |
23 | Correct | 3 ms | 3144 KB | Output is correct |
24 | Correct | 3 ms | 3136 KB | Output is correct |
25 | Correct | 3 ms | 3148 KB | Output is correct |
26 | Correct | 3 ms | 3140 KB | Output is correct |
27 | Correct | 3 ms | 3148 KB | Output is correct |
28 | Correct | 3 ms | 3148 KB | Output is correct |
29 | Correct | 3 ms | 3148 KB | Output is correct |
30 | Correct | 3 ms | 3148 KB | Output is correct |
31 | Correct | 21 ms | 17496 KB | Output is correct |
32 | Correct | 24 ms | 17584 KB | Output is correct |
33 | Correct | 21 ms | 17412 KB | Output is correct |
34 | Correct | 20 ms | 17484 KB | Output is correct |
35 | Correct | 20 ms | 17448 KB | Output is correct |
36 | Correct | 20 ms | 17524 KB | Output is correct |
37 | Correct | 20 ms | 17560 KB | Output is correct |
38 | Correct | 21 ms | 17484 KB | Output is correct |
39 | Correct | 24 ms | 17564 KB | Output is correct |
40 | Correct | 24 ms | 17484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 324 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 460 KB | Output is correct |
8 | Correct | 1 ms | 460 KB | Output is correct |
9 | Correct | 2 ms | 460 KB | Output is correct |
10 | Correct | 1 ms | 460 KB | Output is correct |
11 | Correct | 1 ms | 460 KB | Output is correct |
12 | Correct | 1 ms | 460 KB | Output is correct |
13 | Correct | 1 ms | 460 KB | Output is correct |
14 | Correct | 1 ms | 588 KB | Output is correct |
15 | Correct | 1 ms | 588 KB | Output is correct |
16 | Correct | 1 ms | 588 KB | Output is correct |
17 | Correct | 1 ms | 588 KB | Output is correct |
18 | Correct | 1 ms | 588 KB | Output is correct |
19 | Correct | 1 ms | 588 KB | Output is correct |
20 | Correct | 1 ms | 588 KB | Output is correct |
21 | Correct | 3 ms | 3148 KB | Output is correct |
22 | Correct | 3 ms | 3148 KB | Output is correct |
23 | Correct | 3 ms | 3144 KB | Output is correct |
24 | Correct | 3 ms | 3136 KB | Output is correct |
25 | Correct | 3 ms | 3148 KB | Output is correct |
26 | Correct | 3 ms | 3140 KB | Output is correct |
27 | Correct | 3 ms | 3148 KB | Output is correct |
28 | Correct | 3 ms | 3148 KB | Output is correct |
29 | Correct | 3 ms | 3148 KB | Output is correct |
30 | Correct | 3 ms | 3148 KB | Output is correct |
31 | Correct | 21 ms | 17496 KB | Output is correct |
32 | Correct | 24 ms | 17584 KB | Output is correct |
33 | Correct | 21 ms | 17412 KB | Output is correct |
34 | Correct | 20 ms | 17484 KB | Output is correct |
35 | Correct | 20 ms | 17448 KB | Output is correct |
36 | Correct | 20 ms | 17524 KB | Output is correct |
37 | Correct | 20 ms | 17560 KB | Output is correct |
38 | Correct | 21 ms | 17484 KB | Output is correct |
39 | Correct | 24 ms | 17564 KB | Output is correct |
40 | Correct | 24 ms | 17484 KB | Output is correct |
41 | Correct | 857 ms | 294140 KB | Output is correct |
42 | Correct | 849 ms | 294204 KB | Output is correct |
43 | Correct | 835 ms | 294268 KB | Output is correct |
44 | Correct | 842 ms | 294308 KB | Output is correct |
45 | Correct | 836 ms | 294368 KB | Output is correct |
46 | Correct | 838 ms | 294464 KB | Output is correct |
47 | Correct | 851 ms | 294468 KB | Output is correct |
48 | Correct | 839 ms | 294352 KB | Output is correct |
49 | Correct | 837 ms | 294340 KB | Output is correct |
50 | Correct | 846 ms | 294596 KB | Output is correct |
51 | Correct | 840 ms | 294340 KB | Output is correct |
52 | Correct | 846 ms | 294476 KB | Output is correct |
53 | Correct | 841 ms | 294356 KB | Output is correct |
54 | Correct | 854 ms | 294256 KB | Output is correct |
55 | Correct | 846 ms | 294456 KB | Output is correct |