Submission #774804

#TimeUsernameProblemLanguageResultExecution timeMemory
774804RecursiveCoGroup Photo (JOI21_ho_t3)C++14
100 / 100
687 ms392260 KiB
// 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 (stderr)

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) {
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...