結果
| 問題 | No.3618 Omega Cat(Making ver.) |
| コンテスト | |
| ユーザー |
mocchi
|
| 提出日時 | 2026-08-06 15:56:35 |
| 言語 | C++23(gnu拡張gcc16) (gcc 16.1.0 + boost 1.90.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,539 bytes |
| 記録 | |
| コンパイル時間 | 2,396 ms |
| コンパイル使用メモリ | 365,708 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-08-06 15:56:47 |
| 合計ジャッジ時間 | 8,585 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サンプル | 0 % | RE * 1 |
| 小課題1 | 20 % | WA * 5 |
| 小課題2 | 20 % | WA * 12 |
| 小課題3 | 40 % | WA * 12 RE * 12 |
| 小課題4 | 20 % | WA * 12 RE * 26 |
| 合計 | 3.5 * 0% = 0 点 |
ソースコード
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
constexpr int inf = 1e9;
// from https://drken1215.hatenablog.com/entry/2021/08/09/235400
signed main() {
int T;
cin >> T;
while (T--)
{
int N;
cin >> N;
vector H(N,0LL);
rep(i,N) cin >> H[i];
assert(N <= 8);
int ans = inf;
vector cop(N,0LL);
vector B = H;
// B を小さい順にソート
sort(B.begin(), B.end());
vector<ll> res(H.size());
for (int i = 0; i < H.size(); ++i) {
res[i] = lower_bound(B.begin(), B.end(), H[i]) - B.begin();
}
ranges::iota(cop,0);
do
{
int phase = 0;
if (cop[0] < cop[1])
{
continue;
}
for (int i = 0; i < N - 1; i++)
{
if (phase % 2 == 0)
{
if (cop[i] < cop[i + 1]) phase++;
}
if (phase % 2 == 1)
{
if (cop[i] > cop[i + 1]) phase++;
}
}
if (phase == 3)
{
int cnt = 0;
for (int i = 0; i < N; i++)
{
cnt += (cop[i] != res[i]);
}
ans = min(ans,cnt);
}
}while (ranges::next_permutation(cop).found);
cout << ans << endl;
}
}
mocchi