Submission #499940

# Submission time Handle Problem Language Result Execution time Memory
499940 2021-12-30T05:59:13 Z ac2hu Beautiful row (IZhO12_beauty) C++14
0 / 100
3000 ms 316 KB
#include<bits/stdc++.h>
using namespace std;
bool used[21];
int t2[21],t3[21];
int n;
int ans = 0;
void rec(int last, int num){
	if(num == n){
		used[last] = false;
		ans ++;
	}
	else{
		for(int i = 0;i<n;i++){
			if(!used[i] && (t2[last] == t2[i] || t3[last] == t3[i])){
				used[i] = true;
				rec(i,num + 1);
				used[i] = false;
			}
		}
		used[last] = false;
	}
}
void solve(){
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i<n;i++)cin >> a[i];
	for(int i = 0;i<n;i++){
		t2[i] = 0;
		t3[i] = 0;
		int temp  =a[i];
		while(temp != 0){
			if(temp%2 == 1)
				t2[i]++;
			temp /= 2;
		}
		temp = a[i];
		while(temp != 0){
			t3[i] += (temp%3 == 1);
			temp /= 3;
		}
		// cout << t2[i] << " " << t3[i] << "\n";
	}
	for(int i = 0;i<n;i++){
		used[i] = true;
		rec(i, 1);
		used[i] = false;
	}
	cout << ans << "\n";
}
signed main(){
	iostream::sync_with_stdio(false);
	cin.tie(nullptr);cout.tie(nullptr);
	int T = 1;
	//cin >> T;
	while(T--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 2 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 149 ms 288 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 73 ms 204 KB Output is correct
11 Execution timed out 3083 ms 204 KB Time limit exceeded
12 Halted 0 ms 0 KB -