제출 #321199

#제출 시각아이디문제언어결과실행 시간메모리
321199kshitij_sodani아름다운 순열 (IZhO12_beauty)C++14
100 / 100
833 ms164580 KiB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'

llo n;
llo it[30];
llo co[30];
llo co2[30];
llo dp[1<<20][20];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(llo i=0;i<n;i++){
		cin>>it[i];
		llo x=it[i];
		while(it[i]>0){
			llo xx=it[i]%3;
			if(xx==1){
				co[i]++;
			}
			it[i]-=xx;
			it[i]/=3;
		}
		it[i]=x;
		while(it[i]>0){
			llo xx=it[i]%2;
			if(xx==1){
				co2[i]++;
			}
			it[i]-=xx;
			it[i]/=2;
		}
	}
	llo ans=0;
	for(llo i=1;i<(1<<n);i++){
		vector<llo> co3;
		for(llo j=0;j<n;j++){
			if(i&(1<<j)){
				co3.pb(j);
			}
		}
		if(co3.size()==1){
			dp[i][co3[0]]=1;
		}
		else{
			for(int jj=0;jj<co3.size();jj++){
				int j=co3[jj];
				for(auto k:co3){
					if(co[k]==co[j] or co2[j]==co2[k]){
						dp[i][j]+=dp[i-(1<<j)][k];
					}
				}
			}
		}
		if(co3.size()==n){
			for(llo j=0;j<n;j++){
				ans+=dp[i][j];
			}
		}
	}
	/*for(int i=0;i<n;i++){
		cout<<co[i]<<",,";
	}
	cout<<endl;
	for(int i=0;i<n;i++){
		cout<<co2[i]<<",,";
	}
	cout<<endl;
	cout<<dp[7][0]<<":"<<dp[7][1]<<":"<<dp[7][2]<<endl;
	cout<<dp[3][0]<<":"<<dp[3][1]<<endl;
	cout<<dp[2][1]<<endl;*/
	cout<<ans<<endl;




 
 
	return 0;
}

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

beauty.cpp: In function 'int main()':
beauty.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |    for(int jj=0;jj<co3.size();jj++){
      |                 ~~^~~~~~~~~~~
beauty.cpp:62:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'llo' {aka 'long long int'} [-Wsign-compare]
   62 |   if(co3.size()==n){
      |      ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...