結果
問題 | No.1867 Partitions and Inversions |
ユーザー | SSRS |
提出日時 | 2022-03-04 23:04:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,445 bytes |
コンパイル時間 | 2,356 ms |
コンパイル使用メモリ | 212,260 KB |
実行使用メモリ | 73,984 KB |
最終ジャッジ日時 | 2024-07-18 21:41:19 |
合計ジャッジ時間 | 62,414 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 1,479 ms
73,856 KB |
testcase_03 | AC | 1,492 ms
73,856 KB |
testcase_04 | AC | 1,482 ms
73,856 KB |
testcase_05 | AC | 1,461 ms
73,856 KB |
testcase_06 | AC | 1,452 ms
73,856 KB |
testcase_07 | AC | 1,498 ms
73,856 KB |
testcase_08 | AC | 1,497 ms
73,856 KB |
testcase_09 | AC | 1,459 ms
73,856 KB |
testcase_10 | AC | 1,530 ms
73,856 KB |
testcase_11 | AC | 1,513 ms
73,856 KB |
testcase_12 | AC | 1,468 ms
73,728 KB |
testcase_13 | AC | 1,488 ms
73,856 KB |
testcase_14 | AC | 1,487 ms
73,856 KB |
testcase_15 | AC | 1,461 ms
73,856 KB |
testcase_16 | AC | 1,496 ms
73,856 KB |
testcase_17 | AC | 1,484 ms
73,728 KB |
testcase_18 | AC | 1,604 ms
73,856 KB |
testcase_19 | AC | 1,467 ms
73,856 KB |
testcase_20 | AC | 1,473 ms
73,984 KB |
testcase_21 | AC | 1,445 ms
73,856 KB |
testcase_22 | AC | 1,463 ms
73,856 KB |
testcase_23 | AC | 1,550 ms
73,856 KB |
testcase_24 | AC | 1,481 ms
73,856 KB |
testcase_25 | AC | 1,436 ms
73,856 KB |
testcase_26 | AC | 1,649 ms
73,856 KB |
testcase_27 | AC | 1,463 ms
73,856 KB |
testcase_28 | AC | 1,503 ms
73,856 KB |
testcase_29 | AC | 1,532 ms
73,856 KB |
testcase_30 | WA | - |
testcase_31 | AC | 1,518 ms
73,856 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 23 ms
5,376 KB |
testcase_39 | AC | 24 ms
5,504 KB |
testcase_40 | AC | 23 ms
5,632 KB |
testcase_41 | AC | 22 ms
5,504 KB |
testcase_42 | AC | 22 ms
5,632 KB |
testcase_43 | AC | 509 ms
34,688 KB |
testcase_44 | AC | 528 ms
34,688 KB |
testcase_45 | AC | 522 ms
34,688 KB |
testcase_46 | AC | 498 ms
34,688 KB |
testcase_47 | AC | 500 ms
34,688 KB |
testcase_48 | AC | 513 ms
34,688 KB |
testcase_49 | AC | 500 ms
34,688 KB |
testcase_50 | AC | 507 ms
34,688 KB |
testcase_51 | AC | 538 ms
34,688 KB |
testcase_52 | AC | 507 ms
34,688 KB |
testcase_53 | AC | 533 ms
34,688 KB |
testcase_54 | AC | 504 ms
34,688 KB |
testcase_55 | AC | 509 ms
34,688 KB |
testcase_56 | AC | 508 ms
34,688 KB |
testcase_57 | AC | 500 ms
34,688 KB |
testcase_58 | AC | 510 ms
34,688 KB |
testcase_59 | AC | 508 ms
34,688 KB |
testcase_60 | AC | 501 ms
34,688 KB |
testcase_61 | AC | 504 ms
34,816 KB |
testcase_62 | AC | 497 ms
34,816 KB |
testcase_63 | AC | 1,758 ms
73,856 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 | 1,782 ms
73,856 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
ソースコード
//嘘解法 #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); for (int i = 1; i <= N; i++){ cout << min(-S[0][N] + dp[i][N], -S[0][N] - mx[N + 1 - i]) << endl; } }