# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
447807 | 2021-07-27T14:54:58 Z | cpp219 | Group Photo (JOI21_ho_t3) | C++14 | 286 ms | 67400 KB |
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 5e3 + 9; const ll Log2 = 21; const ll inf = 1e9 + 7; ll n,a[N],pos[N],inv[N][N],dp[N]; int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n; for (ll i = 1;i <= n;i++) cin>>a[i],pos[a[i]] = i; for (ll j = 2;j <= n;j++){ ll now = 0; for (ll i = j - 1;i;i--){ now += (pos[i] > pos[j]); inv[i][j] = inv[i][j - 1] + now; } } for (ll i = 1;i <= n;i++){ dp[i] = inf; for (ll j = i - 1;j >= 0;j--) dp[i] = min(dp[i], dp[j] + inv[1][i] - inv[1][j] + ((i - j)*(i - j - 1))/2 - 2 * inv[j + 1][i]); } cout<<dp[n]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 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 | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 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 | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 320 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 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 | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 320 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 1100 KB | Output is correct |
22 | Correct | 1 ms | 1100 KB | Output is correct |
23 | Correct | 1 ms | 1100 KB | Output is correct |
24 | Correct | 1 ms | 1100 KB | Output is correct |
25 | Correct | 1 ms | 1100 KB | Output is correct |
26 | Correct | 1 ms | 1100 KB | Output is correct |
27 | Correct | 1 ms | 1100 KB | Output is correct |
28 | Correct | 1 ms | 1100 KB | Output is correct |
29 | Correct | 1 ms | 1100 KB | Output is correct |
30 | Correct | 1 ms | 1100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 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 | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 320 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 1100 KB | Output is correct |
22 | Correct | 1 ms | 1100 KB | Output is correct |
23 | Correct | 1 ms | 1100 KB | Output is correct |
24 | Correct | 1 ms | 1100 KB | Output is correct |
25 | Correct | 1 ms | 1100 KB | Output is correct |
26 | Correct | 1 ms | 1100 KB | Output is correct |
27 | Correct | 1 ms | 1100 KB | Output is correct |
28 | Correct | 1 ms | 1100 KB | Output is correct |
29 | Correct | 1 ms | 1100 KB | Output is correct |
30 | Correct | 1 ms | 1100 KB | Output is correct |
31 | Correct | 5 ms | 4804 KB | Output is correct |
32 | Correct | 5 ms | 4684 KB | Output is correct |
33 | Correct | 7 ms | 4800 KB | Output is correct |
34 | Correct | 5 ms | 4800 KB | Output is correct |
35 | Correct | 5 ms | 4812 KB | Output is correct |
36 | Correct | 5 ms | 4684 KB | Output is correct |
37 | Correct | 5 ms | 4812 KB | Output is correct |
38 | Correct | 5 ms | 4812 KB | Output is correct |
39 | Correct | 5 ms | 4684 KB | Output is correct |
40 | Correct | 5 ms | 4684 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 0 ms | 332 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 | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 1 ms | 332 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 332 KB | Output is correct |
17 | Correct | 1 ms | 332 KB | Output is correct |
18 | Correct | 1 ms | 320 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 1100 KB | Output is correct |
22 | Correct | 1 ms | 1100 KB | Output is correct |
23 | Correct | 1 ms | 1100 KB | Output is correct |
24 | Correct | 1 ms | 1100 KB | Output is correct |
25 | Correct | 1 ms | 1100 KB | Output is correct |
26 | Correct | 1 ms | 1100 KB | Output is correct |
27 | Correct | 1 ms | 1100 KB | Output is correct |
28 | Correct | 1 ms | 1100 KB | Output is correct |
29 | Correct | 1 ms | 1100 KB | Output is correct |
30 | Correct | 1 ms | 1100 KB | Output is correct |
31 | Correct | 5 ms | 4804 KB | Output is correct |
32 | Correct | 5 ms | 4684 KB | Output is correct |
33 | Correct | 7 ms | 4800 KB | Output is correct |
34 | Correct | 5 ms | 4800 KB | Output is correct |
35 | Correct | 5 ms | 4812 KB | Output is correct |
36 | Correct | 5 ms | 4684 KB | Output is correct |
37 | Correct | 5 ms | 4812 KB | Output is correct |
38 | Correct | 5 ms | 4812 KB | Output is correct |
39 | Correct | 5 ms | 4684 KB | Output is correct |
40 | Correct | 5 ms | 4684 KB | Output is correct |
41 | Correct | 263 ms | 67308 KB | Output is correct |
42 | Correct | 268 ms | 67328 KB | Output is correct |
43 | Correct | 273 ms | 67344 KB | Output is correct |
44 | Correct | 273 ms | 67348 KB | Output is correct |
45 | Correct | 277 ms | 67232 KB | Output is correct |
46 | Correct | 268 ms | 67268 KB | Output is correct |
47 | Correct | 286 ms | 67368 KB | Output is correct |
48 | Correct | 275 ms | 67332 KB | Output is correct |
49 | Correct | 271 ms | 67316 KB | Output is correct |
50 | Correct | 272 ms | 67340 KB | Output is correct |
51 | Correct | 273 ms | 67368 KB | Output is correct |
52 | Correct | 270 ms | 67272 KB | Output is correct |
53 | Correct | 273 ms | 67400 KB | Output is correct |
54 | Correct | 278 ms | 67256 KB | Output is correct |
55 | Correct | 274 ms | 67368 KB | Output is correct |