제출 #691827

#제출 시각아이디문제언어결과실행 시간메모리
691827iskhakkutbilim아름다운 순열 (IZhO12_beauty)C++14
0 / 100
3058 ms300 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int a[21], binary[21], ternary[21], used[21];
map<int, int> order;
int n, answer;
int ones(int x){
	int s = 0;
	while(x > 0){
		s+= (x%3==1);
		x/= 3;
	}
	return s;
}

void f(int idx, int last){
	if(idx == n){
		answer++;
		return;
	}
	for(int i = 0;i < n; i++){
		if(used[i] == 0){
			if(last == -1){
				used[i] = 1;
				f(idx+1, a[i]);
				used[i] = 0;	
			}else{
				if(binary[i] == binary[order[last]]){
					used[i] = 1;
					f(idx+1, a[i]);
					used[i] = 0;
				}else if(ternary[i] == ternary[order[last]]){
					used[i] = 1;
					f(idx+1, a[i]);
					used[i] = 0;
				}
			}
		}
	}
}

main(){
	cin >> n;
	for(int i = 0;i < n; i++){
		cin >> a[i];
		order[a[i]] = i;
		binary[i] = __builtin_popcount(a[i]);
		ternary[i] = ones(a[i]);
	}
	f(0, -1);
	cout << answer;
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

beauty.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...