結果

問題 No.1867 Partitions and Inversions
ユーザー SSRSSSRS
提出日時 2022-03-04 23:09:02
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,840 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 213,108 KB
実行使用メモリ 75,136 KB
最終ジャッジ日時 2024-07-18 21:46:51
合計ジャッジ時間 80,528 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1,899 ms
75,008 KB
testcase_03 AC 1,937 ms
75,008 KB
testcase_04 AC 1,915 ms
75,008 KB
testcase_05 AC 1,932 ms
75,008 KB
testcase_06 AC 1,843 ms
75,008 KB
testcase_07 AC 1,935 ms
75,008 KB
testcase_08 AC 1,937 ms
75,008 KB
testcase_09 AC 1,864 ms
75,008 KB
testcase_10 AC 1,959 ms
74,880 KB
testcase_11 AC 1,962 ms
75,008 KB
testcase_12 AC 1,931 ms
75,008 KB
testcase_13 AC 1,902 ms
75,136 KB
testcase_14 AC 1,937 ms
75,008 KB
testcase_15 AC 1,875 ms
75,008 KB
testcase_16 AC 1,929 ms
75,008 KB
testcase_17 AC 1,885 ms
75,008 KB
testcase_18 AC 1,995 ms
75,008 KB
testcase_19 AC 1,862 ms
75,008 KB
testcase_20 AC 1,918 ms
75,008 KB
testcase_21 AC 1,868 ms
75,008 KB
testcase_22 AC 1,925 ms
75,008 KB
testcase_23 AC 1,951 ms
75,008 KB
testcase_24 AC 1,818 ms
75,008 KB
testcase_25 AC 1,867 ms
74,880 KB
testcase_26 AC 2,108 ms
75,008 KB
testcase_27 AC 1,844 ms
74,880 KB
testcase_28 AC 1,941 ms
75,008 KB
testcase_29 AC 1,962 ms
75,008 KB
testcase_30 WA -
testcase_31 AC 1,949 ms
75,008 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 35 ms
5,504 KB
testcase_39 AC 35 ms
5,632 KB
testcase_40 AC 35 ms
5,632 KB
testcase_41 AC 34 ms
5,760 KB
testcase_42 AC 35 ms
5,632 KB
testcase_43 AC 703 ms
35,456 KB
testcase_44 AC 710 ms
35,456 KB
testcase_45 AC 714 ms
35,456 KB
testcase_46 AC 687 ms
35,456 KB
testcase_47 AC 703 ms
35,328 KB
testcase_48 AC 721 ms
35,456 KB
testcase_49 AC 703 ms
35,456 KB
testcase_50 AC 710 ms
35,456 KB
testcase_51 AC 729 ms
35,456 KB
testcase_52 AC 714 ms
35,328 KB
testcase_53 AC 707 ms
35,456 KB
testcase_54 AC 703 ms
35,456 KB
testcase_55 AC 716 ms
35,456 KB
testcase_56 AC 688 ms
35,456 KB
testcase_57 AC 700 ms
35,328 KB
testcase_58 AC 692 ms
35,456 KB
testcase_59 AC 708 ms
35,456 KB
testcase_60 AC 705 ms
35,456 KB
testcase_61 AC 699 ms
35,456 KB
testcase_62 AC 677 ms
35,456 KB
testcase_63 AC 2,219 ms
75,008 KB
testcase_64 AC 2 ms
5,376 KB
testcase_65 AC 2 ms
5,376 KB
testcase_66 AC 2 ms
5,376 KB
testcase_67 AC 2,211 ms
75,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:64,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/specfun.h:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/cmath:1935,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:41,
                 from main.cpp:2:
In member function 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value, std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = int]',
    inlined from 'monotone_minima<int, std::less<int> >(int, int, const std::function<int(int, int)>&, const std::less<int>&)::<lambda(int, int, int, int)>' at main.cpp:25:14,
    inlined from 'constexpr _Res std::__invoke_impl(__invoke_other, _Fn&&, _Args&& ...) [with _Res = void; _Fn = monotone_minima<int, std::less<int> >(int, int, const std::function<int(int, int)>&, const std::less<int>&)::<lambda(int, int, int, int)>&; _Args = {int, int, int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/invoke.h:61:36,
    inlined from 'constexpr std::enable_if_t<is_invocable_r_v<_Res, _Callable, _Args ...>, _Res> std::__invoke_r(_Callable&&, _Args&& ...) [with _Res = void; _Callable = monotone_minima<int, std::less<int> >(int, int, const std::function<int(int, int)>&, const std::less<int>&)::<lambda(int, int, int, int)>&; _Args = {int, int, int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/invoke.h:111:28,
    inlined from 'static _Res std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes&& ...) [with _Res = void; _Functor = monotone_minima<int, std::less<int> >(int, int, const std::function<int(int, int)>&, const std::less<int>&)::<lambda(int, int, int, int)>; _ArgTy

ソースコード

diff #

//嘘
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
vector<vector<int>> S;
int op(int i, int j){
  return S[i][j];
}
//https://ei1333.github.io/library/dp/monotone-minima.cpp
template< typename T, typename Compare = less< T > >
vector< pair< int, T > > monotone_minima(int H, int W, const function< T(int, int) > &f, const Compare &comp = Compare()) {
  vector< pair< int, T > > dp(H);
  function< void(int, int, int, int) > dfs = [&](int top, int bottom, int left, int right) {
    if(top > bottom) return;
    int line = (top + bottom) / 2;
    T ma;
    int mi = -1;
    for(int i = left; i <= right; i++) {
      T cst = f(line, i);
      if(mi == -1 || comp(cst, ma)) {
        ma = cst;
        mi = i;
      }
    }
    dp[line] = make_pair(mi, ma);
    dfs(top, line - 1, left, mi);
    dfs(line + 1, bottom, mi, right);
  };
  dfs(0, H - 1, 0, W - 1);
  return dp;
}
//https://ei1333.github.io/library/dp/divide-and-conquer-optimization.cpp
template< typename T, typename Compare = less< T > >
vector< vector< T > > divide_and_conquer_optimization(int H, int W, T INF, const function< T(int, int) > &f, const Compare &comp = Compare()) {
  vector< vector< T > > dp(H + 1, vector< T >(W + 1, INF));
  dp[0][0] = 0;
  for(int i = 1; i <= H; i++) {
    function< T(int, int) > get_cost = [&](int y, int x) {
      if(x >= y) return INF;
      return dp[i - 1][x] + f(x, y);
    };
    auto ret = monotone_minima(W + 1, W + 1, get_cost, comp);
    for(int j = 0; j <= W; j++) dp[i][j] = ret[j].second;
  }
  return dp;
}
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
    P[i]--;
  }
  S = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      if (P[i] > P[j]){
        S[i][j + 1]++;
      }
    }
  }  
  for (int i = 0; i <= N; i++){
    for (int j = 0; j < N; j++){
      S[i][j + 1] += S[i][j];
    }
  }
  for (int i = N; i >= 1; i--){
    for (int j = 0; j <= N; j++){
      S[i - 1][j] += S[i][j];
    }
  }
  vector<int> mx(N + 1, 0);
  for (int i = 0; i <= N; i++){
    for (int j = i; j <= N; j++){
      mx[j - i] = max(mx[j - i], S[i][j]);
      S[i][j] *= -1;
    }
  }
  vector<vector<int>> dp = divide_and_conquer_optimization<int>(N + 1, N + 1, INF, op);
  vector<vector<int>> dp2(101, vector<int>(N + 1, INF));
  dp2[0][0] = 0;
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < N; j++){
      for (int k = j + 1; k <= N; k++){
        dp2[i + 1][k] = min(dp2[i + 1][k], dp2[i][j] + S[j][k]);
      }
    }
  }
  for (int i = 1; i <= N; i++){
    if (i <= 100){
      cout << min({-S[0][N] + dp[i][N], -S[0][N] - mx[N + 1 - i], -S[0][N] + dp2[i][N]}) << endl;
    } else {
      cout << min(-S[0][N] + dp[i][N], -S[0][N] - mx[N + 1 - i]) << endl;
    }
  }
}
0