답안 #282436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
282436 2020-08-24T12:26:29 Z keta_tsimakuridze 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
9 ms 1920 KB
#include<bits/stdc++.h>
using namespace std;
int n,k,b,ones[2][25],cur,a[25],dp[2000005][25],ans;
int main(){
	cin>>n;
	for(k=0;k<n;k++){
		cin>>a[k];
		b=a[k];
		while(b){
			if(b%2) ones[0][k]++;
			b/=2;
		}
		b=a[k];
		while(b){
			if(b%3==1) ones[1][k]++;
			b/=3;
		}
		dp[1<<k][k]=1;
	}
	for(k=1;k<(1<<n);k++){
		for(int j=0;j<n;j++){
			b=1<<j;
			if(! b&k) continue;
			cur=k^b;
		for(int i=0;i<n;i++){
			b=1<<i;
			if(!b&cur) continue;
		//	cout<<k<<" "<<i<<" "<<j<<endl;
			if(ones[0][j]==ones[0][i] || ones[1][j]==ones[1][i]){
			dp[k][j]+=dp[cur][i];// cout<<cur<<" "<<i<<endl;
			
		} }
	//	cout<<k<<"_"<<j<<" "<<dp[k][j]<<endl;
		if(k == ((1<<n) -1)) ans+=dp[k][j];
	} }
	cout<<ans;
}

Compilation message

beauty.cpp: In function 'int main()':
beauty.cpp:23:7: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
   23 |    if(! b&k) continue;
      |       ^~~
beauty.cpp:27:7: warning: suggest parentheses around operand of '!' or change '&' to '&&' or '!' to '~' [-Wparentheses]
   27 |    if(!b&cur) continue;
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Incorrect 9 ms 1920 KB Output isn't correct
12 Halted 0 ms 0 KB -