Submission #1111842

# Submission time Handle Problem Language Result Execution time Memory
1111842 2024-11-13T04:30:04 Z Tsagana Beautiful row (IZhO12_beauty) C++14
0 / 100
9 ms 2516 KB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second

using namespace std;

int l[25];
int s[25][5];
int dp[2000000][25];

int to2(int x) {
	int ans = 0;
	while (x) {if (x%2 == 1) ans++; x /= 2;}
	return ans;
}
int to3(int x) {
	int ans = 0;
	while (x) {if (x%3 == 1) ans++; x /= 3;}
	return ans;
}

void solve () {
	l[0] = 1; for (int i = 1; i <= 20; i++) l[i] = l[i-1]*2;

	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		s[i][2] = to2(x);
		s[i][3] = to3(x);
	}
	for (int i = 0; i < n; i++) dp[l[i]][i] = 1;
	
	for (int i = 0; i < l[n]; i++)
		for (int j = 0; j < n; j++)
		for (int k = 0; k < n; k++) {
			if (i & l[k]) continue ;
			if (s[j][2] == s[k][2] || s[j][3] == s[k][3]) {
				dp[i|l[k]][k] += dp[i][j];
			}
		}
	
	int ans = 0;
	for (int i = 0; i < n; i++) ans += dp[l[n]-1][i];
	cout << ans;
}
int main() {IOS solve(); return 0;}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Incorrect 9 ms 2516 KB Output isn't correct
12 Halted 0 ms 0 KB -