# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
883628 | NintsiChkhaidze | Beautiful row (IZhO12_beauty) | C++17 | 6 ms | 4700 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define pii pair<int,int>
#define ll long long
using namespace std;
const int N = 1e5 + 3;
ll dp[(1<<20) + 3][23];
int p2[23],p3[23],a[23];
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 0; i < n; i++)
cin >> a[i],dp[(1<<i)][i] = 1;
for (int i = 0; i < n; i++){
p2[i] = __builtin_popcount(a[i]);
while (a[i] > 0){
p3[i] += (a[i] % 3 == 1);
a[i] /= 3;
}
}
for (int mask = 0; mask < (1<<n); mask++){
vector <int> on,off;
for (int i=0;i<n;i++){
if (!(mask & (1<<i))) off.pb(i);
else on.pb(i);
}
for (int x: on){
for (int y: off){
if (p2[x] == p2[y] || p3[x] == p3[y])
dp[(mask ^ (1<<y))][y] += dp[mask][x];
}
}
}
int ans = 0;
for (int i = 0; i < n; i++)
ans += dp[(1<<n) - 1][i];
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |