結果
| 問題 | No.1867 Partitions and Inversions |
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2022-03-04 23:04:48 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,445 bytes |
| 記録 | |
| コンパイル時間 | 1,348 ms |
| コンパイル使用メモリ | 221,980 KB |
| 実行使用メモリ | 74,240 KB |
| 最終ジャッジ日時 | 2026-06-25 11:00:14 |
| 合計ジャッジ時間 | 34,292 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 64 WA * 1 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:64,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
from main.cpp:2:
In member function 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)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/15.2.0_1/include/c++/15/bits/invoke.h:63:36,
inlined from 'constexpr std::enable_if_t<((bool)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/15.2.0_1/include/c++/15/bits/invoke.h:113: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)>; _ArgTypes = {int, int, int, int}]' at /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/
ソースコード
//嘘解法
#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;
}
}
SSRS