結果
問題 | No.334 門松ゲーム |
ユーザー |
|
提出日時 | 2018-08-15 19:15:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 859 bytes |
コンパイル時間 | 630 ms |
コンパイル使用メモリ | 65,540 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 09:28:58 |
合計ジャッジ時間 | 1,546 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include<iostream> using namespace std; int n; int ansi = -1, ansj = -1, ansk = -1; int a[20]; bool dfs(int bitmask){ for(int i = 0; i < n-2; i++){ for(int j = i+1; j < n-1; j++){ for(int k = j+1; k < n; k++){ if(~bitmask&(1<<i) && ~bitmask&(1<<j) && ~bitmask&(1<<k) && (a[i]-a[j])*(a[k]-a[j]) > 0 && !dfs(bitmask | (1<<i) | (1<<j) | (1<<k))){ ansi = i, ansj = j, ansk = k; return true; } } } } // bitmask状況下において新しく門松列を作ることが出来ない return false; } int main(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; if(dfs(0)) cout << ansi << " " << ansj << " " << ansk << endl; else cout << -1 << endl; return 0; }