제출 #1168388

#제출 시각아이디문제언어결과실행 시간메모리
1168388SmuggingSpun아름다운 순열 (IZhO12_beauty)C++20
0 / 100
0 ms320 KiB
#include<bits/stdc++.h>
#define taskname "B"
using namespace std;
typedef long long ll;
int count_1(int x, bool is_2){
    if(is_2){
        return __builtin_popcount(x);
    }
    int ans = 0;
    while(x > 0){
        ans += int(x % 3 == 1);
        x /= 3;
    }
    return ans;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
    int n;
    cin >> n;
    vector<int>a(n);
    for(int& x : a){
        cin >> x;
    }
    vector<vector<bool>>g(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(count_1(i, false) == count_1(j, false) || count_1(i, true) == count_1(j, true)){
                g[i][j] = g[j][i] = true;
            }
        }
    }
    vector<vector<ll>>dp(1 << n, vector<ll>(n, 0));
    for(int mask = 1; mask < (1 << n); mask++){
        vector<int>p;
        for(int i = 0; i < n; i++){
            if(1 << i & mask){
                p.emplace_back(i);
            }
        }
        if(p.size() == 1){
            dp[mask][p[0]] = 1;
            continue;
        }
        for(int& i : p){
            for(int& j : p){
                if(i != j && g[i][j]){
                    dp[mask][i] += dp[mask ^ (1 << i)][j];
                }
            }
        }
    }
    cout << accumulate(dp[(1 << n) - 1].begin(), dp[(1 << n) - 1].end(), 0LL);
}

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

beauty.cpp: In function 'int main()':
beauty.cpp:19:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...