結果
| 問題 |
No.334 門松ゲーム
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2018-02-18 22:08:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,594 bytes |
| コンパイル時間 | 1,517 ms |
| コンパイル使用メモリ | 167,828 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 16:45:57 |
| 合計ジャッジ時間 | 2,515 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int N;
int dp[1 << 12];
int K[12];
bool isKadomatsuSequence(int a, int b, int c){
return a != b && b != c && c != a &&
(max({a, b, c}) == b || min({a, b, c}) == b);
}
int rec(int state, int n){
if(n == N){
return -1;
}
if(dp[state] != -2){
return dp[state];
}
dp[state] = -1;
for(int i=0;i<N;++i){
if(state >> i & 1){continue;}
for(int j=i+1;j<N;++j){
if(state >> j & 1){continue;}
for(int k=j+1;k<N;++k){
if(state >> k & 1){continue;}
if(isKadomatsuSequence(K[i], K[j], K[k]) && rec(state | (1 << i) | (1 << j) | (1 << k), n + 3) == -1){
dp[state] = i + ((j + (k << 4)) << 4);
return dp[state];
}
}
}
}
return dp[state];
}
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> N;
for(int i=0;i<N;++i){
std::cin >> K[i];
}
fill(dp, dp + (1 << 12), -2);
int x = rec(0, 0);
if(x == -1){
std::cout << x << std::endl;
}else{
int a = x & 0xf, b = x >> 4 & 0xf, c = x >> 8 & 0xf;
std::cout << a << " " << b << " " << c << std::endl;
}
}
tottoripaper