답안 #885767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885767 2023-12-10T16:16:24 Z Zero 아름다운 순열 (IZhO12_beauty) C++17
0 / 100
600 ms 440 KB
#include <bits/stdc++.h>
using namespace std;

int bt(int n){
	return __builtin_popcount(n);
}
int tr(int n){
	int y = 0;
	while(n){
		if(n%3==1) y++;
		n/=3;
	}
	return y;	
}
bool ok(vector<int> a){
	for(int i=0; i < 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;
}
int main() {
	int n; cin >> n;
	vector<int> a(n);
	for(auto &i : a ) cin >> i;
	sort(a.begin(),a.end());
	int c = 0;
	do{
		c += ok(a);
	}while(next_permutation(a.begin(),a.end()));
	cout << c;
	
    return 0;
}

Compilation message

beauty.cpp: In function 'bool ok(std::vector<int>)':
beauty.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i=0; i < a.size()-1; i ++){
      |               ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 243 ms 412 KB Output is correct
7 Correct 195 ms 348 KB Output is correct
8 Correct 600 ms 348 KB Output is correct
9 Incorrect 112 ms 412 KB Output isn't correct
10 Halted 0 ms 0 KB -