結果
問題 | No.334 門松ゲーム |
ユーザー | aaaaaaiu |
提出日時 | 2019-08-14 13:18:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 2,272 ms |
コンパイル使用メモリ | 202,592 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-19 17:27:01 |
合計ジャッジ時間 | 2,976 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 2 ms
4,348 KB |
testcase_15 | AC | 2 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool iskdmt(int a,int b,int c) { return (a<b&&c<b||b<a&&b<c)&&a!=c; } bool dfs(int x, int n, int a[]) { for (int i=0;i<n;i++) { if (x&1<<i) continue; for (int j=i+1;j<n;j++) { if (x&1<<j) continue; for (int k=j+1;k<n;k++) { if (x&1<<k) continue; if (!iskdmt(a[i],a[j],a[k])) continue; if (!dfs(x|1<<i|1<<j|1<<k,n,a)) return true; } } } return false; } int main() { int n; cin>>n; int a[n]; for (int i=0;i<n;i++) cin>>a[i]; for (int i=0;i<n;i++) for (int j=i+1;j<n;j++) for (int k=j+1;k<n;k++) { if (!iskdmt(a[i],a[j],a[k])) continue; if (!dfs(1<<i|1<<j|1<<k,n,a)) { cout<<i<<' '<<j<<' '<<k<<endl; return 0; } } cout<<-1<<endl; return 0; }