답안 #89276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89276 2018-12-11T08:27:08 Z Badral 아름다운 순열 (IZhO12_beauty) C++17
100 / 100
1113 ms 165124 KB
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
ll a[55], n, b[55][55];
 
ll gurav(ll x) {ll s = 0; while (x) {s += (x % 3 == 1); x /= 3; } return s; }
ll hoyr(ll x) {ll s = 0; while (x) {s += (x % 2 == 1); x /= 2; } return s; }
ll c[1 << 20][20], ans;

int main() {
	ll n;
	cin >>n;
	for(ll i = 0; i < n; i++) {
		ll x;
		cin >>x;
		a[i] = x;
		c[1 << i][i]++;
	}
	for(ll i = 0; i < n; i++) 
		for(ll j = 0; j < n; j++) 
			if(gurav(a[i]) == gurav(a[j]) || hoyr(a[i]) == hoyr(a[j])) 
				b[i][j] = 1;

	for(ll i = 1; i < (1 << n); i++)
		for(ll j = 0; j < n; j++) {
      		if((i >> j) & 1 ^ 1) continue;
			for(ll k = 0; k < n; k++) 
				if(((i >> k) & 1 ^ 1) && b[j][k]) 
					c[i | (1 << k)][k] += c[i][j];
		}

	for(ll i = 0; i < n; i++) ans += c[(1 << n) - 1][i];
	cout<<ans;
}

Compilation message

beauty.cpp: In function 'int main()':
beauty.cpp:28:21: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
         if((i >> j) & 1 ^ 1) continue;
            ~~~~~~~~~^~~
beauty.cpp:30:18: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     if(((i >> k) & 1 ^ 1) && b[j][k]) 
         ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 700 KB Output is correct
4 Correct 2 ms 700 KB Output is correct
5 Correct 2 ms 824 KB Output is correct
6 Correct 3 ms 884 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 2 ms 892 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 3 ms 900 KB Output is correct
11 Correct 12 ms 3380 KB Output is correct
12 Correct 11 ms 3400 KB Output is correct
13 Correct 48 ms 11024 KB Output is correct
14 Correct 226 ms 41808 KB Output is correct
15 Correct 205 ms 41960 KB Output is correct
16 Correct 216 ms 42000 KB Output is correct
17 Correct 233 ms 42000 KB Output is correct
18 Correct 243 ms 42000 KB Output is correct
19 Correct 1113 ms 165124 KB Output is correct
20 Correct 952 ms 165124 KB Output is correct