Submission #673275

# Submission time Handle Problem Language Result Execution time Memory
673275 2022-12-20T05:18:18 Z Alihan_8 Beautiful row (IZhO12_beauty) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vector <int> p(n);
    for ( auto &I: p ) cin >> I;
    vector <array<int,2>> bits(n);
    for ( int i = 0; i < n; i++ ){
        int cnt = 0, val = p[i];
        while ( val ){
            cnt += val & 1;
            val >>= 1;
        }
        val = p[i];
        bits[i][0] = cnt;
        cnt = 0;
        while ( val ){
            cnt += val%3 == 1;
            val /= 3;
        }
        bits[i][1] = cnt;
    }
    const int S = 1 << n;
    vector <vector<int>> dp(S, vector <int> (n));
    auto same = [&](int i, int j){
        for ( auto val: bits[i] ){
            for ( auto _val: bits[j] ){
                if ( _val == val ) return true;
            }
        }
        return false;
    };
    for ( int i = 0; i < n; i++ ) dp[1 << i][i] = 1;
    auto chmax = [&](int &l, int r){l = max(l, r);};
    for ( int mask = 1; mask < S; mask++ ){
        for ( int i = 0; i < n; i++ ){
            if ( mask >> i & 1 ){
                for ( int j = 0; j < n; j++ ){
                    if ( mask >> j & 1 ) continue;
                    int v = mask | (1 << j);
                    if ( !same(i, j) ) continue;
                    dp[v][j] += dp[mask][i];
                }
            }
        }
    }
    int cnt = 0;
    for ( int i = 0; i < n; i++ ) cnt += dp[S-1][i];
    cout << cnt;

    cout << '\n';
}

Compilation message

beauty.cpp: In function 'int main()':
beauty.cpp:47:10: warning: variable 'chmax' set but not used [-Wunused-but-set-variable]
   47 |     auto chmax = [&](int &l, int r){l = max(l, r);};
      |          ^~~~~
beauty.cpp: In function 'void IO(std::string)':
beauty.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
beauty.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -