Submission #716474

# Submission time Handle Problem Language Result Execution time Memory
716474 2023-03-30T06:57:11 Z vjudge1 Beautiful row (IZhO12_beauty) C++17
0 / 100
728 ms 164544 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
struct segment{int l, r, id;
int size(){return r-l+1;}};
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 1e6 + 1;
const ll INF = (1ll<<61);
const int MOD = 1e9 + 7;
const int inf = (1<<30);
const int maxl = 20;
const int P = 31;

int n;
int a[maxn];
int b[maxn];
ll dp[maxn][maxl];

void test(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        a[i] = __builtin_popcount(x);
        while(x){
            b[i] += (x % 3) == 1;
            x /= 3;
        }
    }
    for(int mask = 1; mask < (1<<n); mask++){
        if(__builtin_popcount(mask) == 1){
            for(int i = 0; i < n; i++){
                if(mask & (1<<i)) dp[mask][i] = 1;
            }
        } else{
            for(int i = 0; i < n; i++){
                if(!(mask & (1<<i))) continue;
                for(int j = 0; j < n; j++){
                    if(j == i) continue;
                    if(!(mask & (1<<j))) continue;
                    if(a[i] != a[j] && b[i] != b[j]) continue;
                    dp[mask][i] += dp[mask ^ (1<<i)][j];
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += dp[(1<<n) - 1][i];
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0), cout.tie(0);
    int t; t = 1;
    while(t--) test();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 8 ms 2900 KB Output is correct
12 Correct 7 ms 2900 KB Output is correct
13 Correct 31 ms 10572 KB Output is correct
14 Correct 150 ms 41328 KB Output is correct
15 Correct 145 ms 41356 KB Output is correct
16 Correct 156 ms 41368 KB Output is correct
17 Correct 160 ms 41312 KB Output is correct
18 Correct 158 ms 41356 KB Output is correct
19 Incorrect 728 ms 164544 KB Output isn't correct
20 Halted 0 ms 0 KB -