# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1111843 | Tsagana | 아름다운 순열 (IZhO12_beauty) | C++14 | 1250 ms | 205640 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
int l[25];
int s[25][5];
int dp[2000000][25];
int to2(int x) {
int ans = 0;
while (x) {if (x%2 == 1) ans++; x /= 2;}
return ans;
}
int to3(int x) {
int ans = 0;
while (x) {if (x%3 == 1) ans++; x /= 3;}
return ans;
}
void solve () {
l[0] = 1; for (int i = 1; i <= 20; i++) l[i] = l[i-1]*2;
int n; cin >> n;
for (int i = 0; i < n; i++) {
int x; cin >> x;
s[i][2] = to2(x);
s[i][3] = to3(x);
}
for (int i = 0; i < n; i++) dp[l[i]][i] = 1;
for (int i = 0; i < l[n]; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) {
if (i & l[k]) continue ;
if (s[j][2] == s[k][2] || s[j][3] == s[k][3]) {
dp[i|l[k]][k] += dp[i][j];
}
}
int ans = 0;
for (int i = 0; i < n; i++) ans += dp[l[n]-1][i];
cout << ans;
}
signed main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |