답안 #774804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774804 2023-07-06T03:37:02 Z RecursiveCo Group Photo (JOI21_ho_t3) C++14
100 / 100
687 ms 392260 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long int

signed main() {
    improvePerformance;
    get(n);
    getList(n, nums);
    forto(n, i) nums[i]--;
    vector<int> dp(n);
    vector<vector<int>> inv(n, vector<int>(n, 0));
    vector<vector<int>> invinv(n, vector<int>(n, 0));
    forto(n, i) {
        for (int j = i + 1; j < n; j++) {
            if (nums[i] > nums[j]) inv[nums[j]][nums[i]] = 1;
            else invinv[nums[i]][nums[j]] = 1;
        }
    }
    vector<int> cnt(n, 0);
    forto(n, i) {
        forto(n, j) {
            cnt[j] += invinv[j][i];
            cnt[i] += inv[i][j];
        }
        forto(i, j) {
            cnt[j] -= inv[j][i];
        }
        int el = 1e18;
        int c = 0;
        forto(i + 1, s) {
            int sz = s + 1;
            int cur = i - sz == -1? 0: dp[i - sz];
            int j = i - sz + 1;
            c += cnt[j];
            cur += c;
            el = min(el, cur);
        }
        dp[i] = el;
    }
    out(dp[n - 1]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:22:5: note: in expansion of macro 'get'
   22 |     get(n);
      |     ^~~
Main.cpp:12:40: warning: unnecessary parentheses in declaration of 'nums' [-Wparentheses]
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                        ^
Main.cpp:23:5: note: in expansion of macro 'getList'
   23 |     getList(n, nums);
      |     ^~~~~~~
Main.cpp:10:23: warning: unnecessary parentheses in declaration of 'a' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
Main.cpp:12:76: note: in expansion of macro 'get'
   12 | #define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
      |                                                                            ^~~
Main.cpp:23:5: note: in expansion of macro 'getList'
   23 |     getList(n, nums);
      |     ^~~~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:24:5: note: in expansion of macro 'forto'
   24 |     forto(n, i) nums[i]--;
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:28:5: note: in expansion of macro 'forto'
   28 |     forto(n, i) {
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:35:5: note: in expansion of macro 'forto'
   35 |     forto(n, i) {
      |     ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:36:9: note: in expansion of macro 'forto'
   36 |         forto(n, j) {
      |         ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:40:9: note: in expansion of macro 'forto'
   40 |         forto(i, j) {
      |         ^~~~~
Main.cpp:15:35: warning: unnecessary parentheses in declaration of 's' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
Main.cpp:45:9: note: in expansion of macro 'forto'
   45 |         forto(i + 1, s) {
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 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 212 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 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 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 212 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 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 852 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 1 ms 852 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 1 ms 852 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 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 212 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 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 852 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 1 ms 852 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 1 ms 852 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 7 ms 10304 KB Output is correct
32 Correct 7 ms 10304 KB Output is correct
33 Correct 7 ms 10308 KB Output is correct
34 Correct 7 ms 10328 KB Output is correct
35 Correct 7 ms 10324 KB Output is correct
36 Correct 7 ms 10324 KB Output is correct
37 Correct 7 ms 10324 KB Output is correct
38 Correct 7 ms 10384 KB Output is correct
39 Correct 8 ms 10432 KB Output is correct
40 Correct 8 ms 10324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 212 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 212 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 316 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 852 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 1 ms 852 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 1 ms 852 KB Output is correct
28 Correct 2 ms 852 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 7 ms 10304 KB Output is correct
32 Correct 7 ms 10304 KB Output is correct
33 Correct 7 ms 10308 KB Output is correct
34 Correct 7 ms 10328 KB Output is correct
35 Correct 7 ms 10324 KB Output is correct
36 Correct 7 ms 10324 KB Output is correct
37 Correct 7 ms 10324 KB Output is correct
38 Correct 7 ms 10384 KB Output is correct
39 Correct 8 ms 10432 KB Output is correct
40 Correct 8 ms 10324 KB Output is correct
41 Correct 662 ms 391788 KB Output is correct
42 Correct 632 ms 391936 KB Output is correct
43 Correct 632 ms 392016 KB Output is correct
44 Correct 669 ms 391912 KB Output is correct
45 Correct 639 ms 392016 KB Output is correct
46 Correct 650 ms 392248 KB Output is correct
47 Correct 645 ms 392256 KB Output is correct
48 Correct 666 ms 392252 KB Output is correct
49 Correct 687 ms 392172 KB Output is correct
50 Correct 645 ms 392260 KB Output is correct
51 Correct 656 ms 392256 KB Output is correct
52 Correct 661 ms 392248 KB Output is correct
53 Correct 643 ms 392252 KB Output is correct
54 Correct 668 ms 392256 KB Output is correct
55 Correct 655 ms 392248 KB Output is correct