| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 21875 | ulna | Beautiful row (IZhO12_beauty) | C++11 | 1033 ms | 165860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// why am I so weak
int n;
int a[25];
long long dp[1 << 20][20];
bool adj[25][25];
inline bool gao(int x, int y, int t) {
int a = 0;
while (x > 0) {
if (x % t == 1) a++;
x /= t;
}
while (y > 0) {
if (y % t == 1) a--;
y /= t;
}
return a == 0;
}
bool trial(int x, int y) {
return gao(x, y, 2) || gao(x, y, 3);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
dp[1 << i][i] = 1;
}
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
adj[i][j] = trial(a[i], a[j]);
}
for (int mask = 0; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) if (dp[mask][i] > 0) {
for (int j = 0; j < n; j++) if (!(mask & (1 << j)) && adj[i][j]) {
dp[mask | (1 << j)][j] += dp[mask][i];
}
}
}
long long res = 0ll;
for (int i = 0; i < n; i++) res += dp[(1 << n) - 1][i];
printf("%lld\n", res);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
