# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
499809 |
2021-12-29T15:05:18 Z |
Lobo |
Group Photo (JOI21_ho_t3) |
C++17 |
|
34 ms |
444 KB |
#include<bits/stdc++.h>
using namespace std;
/*for ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
*/
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 220
ii n, a[maxn], pos[maxn], bit[maxn], dp[maxn], mark[maxn];
void att(ii id, ii val) {
for(ii i = id; i <= n; i+= i&-i) {
bit[i]+= val;
}
}
ii qr(ii id) {
ii val = 0;
for(ii i = id; i > 0; i-= i&-i) {
val+= bit[i];
}
return val;
}
ii sol(ii i) {
if(mark[i]) return dp[i];
mark[i] = 1;
ii ans = INFii;
if(i == n) return dp[i] = 0;
for(ii k = i+1; k <= n; k++) {
ii ans1 = 0;
for(ii j = 1; j <= n; j++) {
bit[j] = 0;
}
for(ii j = 1; j <= i; j++) {
att(pos[j],1);
}
for(ii j = k; j >= i+1; j--) {
ans1+= j-1-qr(pos[j]);
att(pos[j],+1);
}
ans = min(ans, ans1+sol(k));
}
return dp[i] = ans;
}
void solve() {
cin >> n;
for(ii i = 1; i <= n; i++) {
cin >> a[i];
pos[a[i]] = i;
}
cout << sol(0) << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
ii tt = 1;
// cin >> tt;
while(tt--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 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 |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 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 |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
26 ms |
332 KB |
Output is correct |
22 |
Correct |
27 ms |
204 KB |
Output is correct |
23 |
Correct |
26 ms |
332 KB |
Output is correct |
24 |
Correct |
27 ms |
308 KB |
Output is correct |
25 |
Correct |
27 ms |
336 KB |
Output is correct |
26 |
Correct |
27 ms |
204 KB |
Output is correct |
27 |
Correct |
28 ms |
204 KB |
Output is correct |
28 |
Correct |
30 ms |
312 KB |
Output is correct |
29 |
Correct |
34 ms |
316 KB |
Output is correct |
30 |
Correct |
30 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
26 ms |
332 KB |
Output is correct |
22 |
Correct |
27 ms |
204 KB |
Output is correct |
23 |
Correct |
26 ms |
332 KB |
Output is correct |
24 |
Correct |
27 ms |
308 KB |
Output is correct |
25 |
Correct |
27 ms |
336 KB |
Output is correct |
26 |
Correct |
27 ms |
204 KB |
Output is correct |
27 |
Correct |
28 ms |
204 KB |
Output is correct |
28 |
Correct |
30 ms |
312 KB |
Output is correct |
29 |
Correct |
34 ms |
316 KB |
Output is correct |
30 |
Correct |
30 ms |
320 KB |
Output is correct |
31 |
Runtime error |
1 ms |
444 KB |
Execution killed with signal 11 |
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 |
316 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
26 ms |
332 KB |
Output is correct |
22 |
Correct |
27 ms |
204 KB |
Output is correct |
23 |
Correct |
26 ms |
332 KB |
Output is correct |
24 |
Correct |
27 ms |
308 KB |
Output is correct |
25 |
Correct |
27 ms |
336 KB |
Output is correct |
26 |
Correct |
27 ms |
204 KB |
Output is correct |
27 |
Correct |
28 ms |
204 KB |
Output is correct |
28 |
Correct |
30 ms |
312 KB |
Output is correct |
29 |
Correct |
34 ms |
316 KB |
Output is correct |
30 |
Correct |
30 ms |
320 KB |
Output is correct |
31 |
Runtime error |
1 ms |
444 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |