| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 716444 | vjudge1 | 아름다운 순열 (IZhO12_beauty) | C++17 | 6 ms | 7380 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int P = 5;
const int K = 110;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 100;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const string C[] = {"NO\n", "YES\n"};
int n;
int a[maxn];
vector<int>g[maxn];
ll dp[20][(1<<20)];
bool ok(int x, int y){
if(__builtin_popcount(x) == __builtin_popcount(y)) return 1;
int cnt = 0;
while(x){
if(x%3 == 1) cnt++;
x /= 3;
}
while(y){
if(y%3 == 1) cnt--;
y /= 3;
}
return (cnt == 0);
}
int main(){
freopen("b.in", "r", stdin);
freopen("b.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for(int i=0; i<n; i++){
cin >> a[i];
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(ok(a[i], a[j])){
g[i].pb(j);
}
}
dp[i][1<<i] = 1;
}
for(int mask=1; mask<(1<<n); mask++){
for(int i=0; i<n; i++){
if(!bit(mask, i)) continue;
for(auto to: g[i]){
if(bit(mask, to)) continue;
dp[to][mask^(1<<to)] += dp[i][mask];
}
}
}
ll ans = 0;
for(int i=0; i<n; i++) ans += dp[i][(1<<n)-1];
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
