結果
| 問題 | 
                            No.360 増加門松列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             koyumeishi
                         | 
                    
| 提出日時 | 2016-04-17 03:32:40 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 887 bytes | 
| コンパイル時間 | 853 ms | 
| コンパイル使用メモリ | 76,120 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-24 04:29:22 | 
| 合計ジャッジ時間 | 1,730 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool is_kadomatsu(int a, int b, int c){
	if(a==b || b==c || c==a) return false;
	if(a<b && b>c) return true;
	if(a>b && b<c) return true;
	return false;
}
int main(){
	int n = 7;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	
	for(int i=0; i<(1<<n); i++){
		if( __builtin_popcount(i) != (n+1)/2 ) continue;
		
		vector<int> b(n);
		int x = 0, y = 1;
		for(int j=0; j<n; j++){
			if((i>>j)&1){
				b[x] = a[j];
				x += 2;
			}else{
				b[y] = a[j];
				y += 2;
			}
		}
		bool ok = true;
		for(int j=2; j<n; j++){
			if( is_kadomatsu(b[j-2], b[j-1], b[j]) && b[j-2]<b[j] ) continue;
			ok = false;
		}
		if(ok){
			for(int j=0; j<n; j++){
				cerr << b[j] << " ";
			}cerr << endl;
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}
            
            
            
        
            
koyumeishi