結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-28 11:56:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,440 bytes |
| コンパイル時間 | 705 ms |
| コンパイル使用メモリ | 70,808 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-02-28 11:56:38 |
| 合計ジャッジ時間 | 1,912 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:16:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | rep(i,n)scanf("%d",&ipt[i]),ipt[i]--;
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<iostream>
#include<vector>
#include<cassert>
#define rep(i,n) for(i=0;i<(int)(n);i++)
#define MAX_K 20
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n;
int main(){
int i,j,a,b,c;
scanf("%d",&n);
vector<int> ipt(n);
rep(i,n)scanf("%d",&ipt[i]),ipt[i]--;
auto rec=[&](auto& f,int state)->bool{
int i,j,k;
vector<bool> is_used(MAX_K,false);
vector<int> ids;
rep(i,n)if((state>>i)&1)ids.push_back(i);
rep(i,ids.size()){
is_used[ipt[ids[i]]]=true;state^=(1<<ids[i]);
if(ids.size()==(int)n)a=ids[i];
for(j=i+1;j<ids.size();j++){
if(is_used[ipt[ids[j]]])break;
if(ids.size()==(int)n)b=ids[j];
is_used[ipt[ids[j]]]=true;state^=(1<<ids[j]);
for(k=j+1;k<ids.size();k++){
if(is_used[ipt[ids[k]]])break;
if(ids.size()==(int)n)c=ids[k];
if((max(ipt[ids[i]],max(ipt[ids[j]],ipt[ids[k]]))==ipt[ids[j]]||min(ipt[ids[i]],min(ipt[ids[j]],ipt[ids[k]]))==ipt[ids[j]])&&(f(f,state^(1<<ids[k]))==false))return true;
}
is_used[ipt[ids[j]]]=false;state^=(1<<ids[j]);
}
is_used[ipt[ids[i]]]=false;state^=(1<<ids[i]);
}
return false;
};
if(rec(rec,(1<<n)-1))printf("%d %d %d\n",a,b,c);
else puts("-1");
return 0;
}