結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-11 21:49:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 735 bytes |
| コンパイル時間 | 1,637 ms |
| コンパイル使用メモリ | 166,540 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 21:49:17 |
| 合計ジャッジ時間 | 2,603 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 20;
ll n, x, y, z;
ll a[N];
bool f(ll S)
{
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
for (int k = j + 1; k < n; k++)
{
if (~S & (1 << i) && ~S & (1 << j) && ~S & (1 << k))
{
if ((a[i] > a[j] && a[j] < a[k] && a[i] != a[k]) || (a[i] < a[j] && a[j] > a[k] && a[i] != a[k]))
{
if (!f(S ^ (1 << i) ^ (1 << j) ^ (1 << k)))
{
x = i, y = j, z = k;
return true;
}
}
}
}
}
}
return false;
}
int main()
{
scanf("%lld", &n);
for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
if (f(0)) printf("%lld %lld %lld\n", x, y, z);
else printf("-1\n");
return 0;
}