結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-27 18:13:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 648 bytes |
| コンパイル時間 | 2,657 ms |
| コンパイル使用メモリ | 190,996 KB |
| 最終ジャッジ日時 | 2025-01-10 02:30:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int n,a[12];
int ans[3];
bool dfs(int S){
rep(i,n) if(S>>i&1) {
for(int j=i+1;j<n;j++) if(S>>j&1 && a[i]!=a[j]) {
for(int k=j+1;k<n;k++) if(S>>k&1 && a[k]!=a[i] && a[k]!=a[j]) {
if(min({a[i],a[j],a[k]})==a[j] || max({a[i],a[j],a[k]})==a[j]){
if(!dfs(S&~(1<<i)&~(1<<j)&~(1<<k))){
ans[0]=i;
ans[1]=j;
ans[2]=k;
return true;
}
}
}
}
}
return false;
}
int main(){
scanf("%d",&n);
rep(i,n) scanf("%d",&a[i]);
if(!dfs((1<<n)-1)) puts("-1");
else printf("%d %d %d\n",ans[0],ans[1],ans[2]);
return 0;
}