Submission #716440

# Submission time Handle Problem Language Result Execution time Memory
716440 2023-03-30T06:06:19 Z vjudge1 Beautiful row (IZhO12_beauty) C++17
0 / 100
766 ms 164420 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 i = 1; i < (1<<n); i++){
        if(__builtin_popcount(i) == 1){
            for(int j = 0; j < n; j++){
                if(i & (1<<j)) dp[i][j] = 1;
            }
        } else{
            for(int j = 0; j < n; j++){
                if(i & (1<<j)){
                    for(int k = 0; k < n; k++){
                        if(j == k) continue;
                        if(!(i & (1<<k))) continue;
                        if(a[j] != a[k] && b[j] != b[k]) continue;
                        dp[i][j] += dp[i ^ (1<<j)][k];
                    }
                }
            }
        }
    }
    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 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 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 9 ms 2872 KB Output is correct
12 Correct 7 ms 2900 KB Output is correct
13 Correct 33 ms 10540 KB Output is correct
14 Correct 158 ms 41300 KB Output is correct
15 Correct 143 ms 41240 KB Output is correct
16 Correct 163 ms 41292 KB Output is correct
17 Correct 171 ms 41344 KB Output is correct
18 Correct 176 ms 41292 KB Output is correct
19 Incorrect 766 ms 164420 KB Output isn't correct
20 Halted 0 ms 0 KB -