# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
167026 | Hideo | Beautiful row (IZhO12_beauty) | C++14 | 14 ms | 1656 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Need to git gud and reach 1900+
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define prev prev123
#define next next123
#define pow pow123
#define left left123
#define right right123
const int N = 27;
const int INF = 1e9 + 7;
int dp[(1 << 20) + 1][21];
int bin[N], ter[N];
int n;
main(){ // If you don't know what to do, check the text box at the bottom
cin >> n;
for (int i = 0; i < n; i++){
int a;
scanf("%d", &a);
for (int j = 0; j < 31; j++){
if (a & (1 << j))
bin[i]++;
}
int t = a;
while (t){
if (t % 3 == 1)
ter[i]++;
t /= 3;
}
}
for (int mask = 1; mask < (1 << n); mask++){
for (int bit = 0; bit < n; bit++){
if (mask & (1 << bit) && mask ^ (1 << bit)){
for (int last = 0; last < n; last++){
if (last == bit)
continue;
if (mask & (1 << last) && (ter[bit] == ter[last]
|| bin[bit] == bin[last]))
dp[mask][bit] += dp[mask ^ (1 << bit)][last];
}
}
else if (mask & (1 << bit))
dp[mask][bit]++;
}
}
int ans = 0;
for (int i = 0; i < n; i++)
ans += dp[(1 << n) - 1][i];
cout << ans << endl;
}
/*
Totally not inspired by BenQ's template
Things you should do:
1. Look for stupid typos in code e.g 1 instead of -1 etc
2. Check if there is no infinite loops
3. "Measure twice, cut once"
4. Stay focused
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |