# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
90114 | 2018-12-20T11:12:17 Z | Aydarov03 | 아름다운 순열 (IZhO12_beauty) | C++14 | 575 ms | 580 KB |
#include <bits/stdc++.h> #define int long long using namespace std; int a[30]; int st[30]; bool used[30]; int n , ans; int was[ 30 ][ 30 ]; map <int,int> bin; map <int,int> ter; void rec( int k ) { if( k == n + 1 ) { ans++; return; } int ls = ans; for(int i = 1; i <= n; i++) { if( k == 1 || ( !used[i] && ( ter[a[i]] == ter[st[k-1]] || bin[a[i]] == bin[st[k-1]] ) ) ) { st[k] = a[i]; used[ i ] = true; rec( k + 1 ); if( ls != ans ) { int sm = a[i]; int raz = ans - ls; while( 1 ) { i++; if( sm == a[i] )ans += raz; else break; } i--; } used[ i ] = false; } } } void to_bin( int a ) { int one = 0; int A = a; while( a > 0 ) { one += ( a % 2 == 1); a /= 2; } bin[ A ] = one; } void to_ter( int a ) { int one = 0; int A = a; while( a > 0 ) { one += ( a % 3 == 1); a /= 3; } ter[ A ] = one; } main() { scanf("%lld" , &n); for(int i = 1; i <= n; i++)scanf("%lld" , &a[i]); sort( a + 1 , a + n + 1 ); for(int i = 1; i <= n; i++) { to_bin( a[i] ); to_ter( a[i] ); } rec(1); printf("%lld" , ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 1 ms | 508 KB | Output is correct |
3 | Correct | 2 ms | 508 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 508 KB | Output is correct |
6 | Correct | 9 ms | 508 KB | Output is correct |
7 | Correct | 2 ms | 512 KB | Output is correct |
8 | Correct | 575 ms | 580 KB | Output is correct |
9 | Incorrect | 3 ms | 580 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |