Submission #839110

#TimeUsernameProblemLanguageResultExecution timeMemory
83911042kangarooGroup Photo (JOI21_ho_t3)C++17
100 / 100
257 ms395620 KiB
// // Created by 42kangaroo on 28/08/2023. // #include "bits/stdc++.h" using namespace std; #define int long long vector<vector<int>> weightF(vector<int>& a) { // get inversion direction vector<vector<bool>> dI(a.size() + 1, vector<bool>(a.size() + 1)); for (int i = 0; i < a.size(); ++i) { for (int j = 0; j < i; ++j) { if (a[i] > a[j]) { dI[a[i]][a[j]] = true; // second is greater } else { dI[a[j]][a[i]] = false; } } } // add to new as dif array vector<vector<int>> cD(a.size() + 1, vector<int>(a.size() + 1, 0)); for (int i = 1; i < cD.size(); ++i) { int le = 0; for (int j = 1; j < i; ++j) { cD[i][j] = (dI[i][j] ? 1 : -1); le += !dI[i][j]; } cD[i][i] = le; } // calc dif array vector<vector<int>> c(a.size() + 1, vector<int>(a.size() + 1, 0)); for (int i = 1; i < c.size(); ++i) { for (int j = i; j >= 0; --j) { if (j != c.size() - 1) c[i][j] += cD[i][j + 1] + c[i][j + 1]; } for (int j = i; j >= 0; --j) { c[i][j] += c[i - 1][j]; } } return c; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } vector<int> dp(n + 1, 1e9); dp[0] = 0; vector<vector<int>> c = weightF(a); for (int i = 1; i <= n; ++i) { for (int j = 0; j < i; ++j) { dp[i] = min(dp[i], dp[j] + c[i][j]); } } cout << dp[n]; }

Compilation message (stderr)

Main.cpp: In function 'std::vector<std::vector<long long int> > weightF(std::vector<long long int>&)':
Main.cpp:13:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0; i < a.size(); ++i) {
      |                  ~~^~~~~~~~~~
Main.cpp:24:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 1; i < cD.size(); ++i) {
      |                  ~~^~~~~~~~~~~
Main.cpp:34:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 1; i < c.size(); ++i) {
      |                  ~~^~~~~~~~~~
Main.cpp:36:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |    if (j != c.size() - 1) c[i][j] += cD[i][j + 1] + c[i][j + 1];
      |        ~~^~~~~~~~~~~~~~~
#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...