제출 #673277

#제출 시각아이디문제언어결과실행 시간메모리
673277Alihan_8아름다운 순열 (IZhO12_beauty)C++17
100 / 100
868 ms205552 KiB
#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 ( int k = 0; k < 2; k++ ){
            if ( bits[i][k] == bits[j][k] ) return true;
        }
        return false;
    };
    for ( int i = 0; i < n; i++ ) dp[1 << i][i] = 1;
    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';
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...