# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1168388 | SmuggingSpun | Beautiful row (IZhO12_beauty) | C++20 | 0 ms | 320 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) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |