답안 #885771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885771 2023-12-10T16:27:33 Z Zero 아름다운 순열 (IZhO12_beauty) C++17
0 / 100
568 ms 596 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int bt(int n){
	return __builtin_popcountll(n);
}
int tr(int n){
    int c = 0;
    if (!n)return 0;

    while (n > 0) {
        int r = n % 3;
        if(r==1)c++;
        n/= 3;
    }

    return c;
}
bool ok(vector<int> a){
	for(int i=0; i < (int)a.size()-1; i ++){
		int b1 = bt(a[i]), t1 = tr(a[i]);
		int b2 = bt(a[i+1]), t2 = tr(a[i+1]);
		if(b1 != b2 && t1 != t2) return 0;
	}
	return 1;
}
signed main() {
	int n; cin >> n;
	vector<int> a(n);
	int z = 0;
	for(auto &i : a ){
		cin >> i;
		if(!i)z++;
	}
	if(z) return cout << 0,0;
	sort(a.begin(),a.end());
	int c = 0;
	do{
		c += ok(a);
	}while(next_permutation(a.begin(),a.end()));
	cout << c;
	
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 225 ms 348 KB Output is correct
7 Correct 184 ms 408 KB Output is correct
8 Correct 568 ms 412 KB Output is correct
9 Incorrect 107 ms 596 KB Output isn't correct
10 Halted 0 ms 0 KB -