| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 90110 | Aydarov03 | 아름다운 순열 (IZhO12_beauty) | C++14 | 3032 ms | 620 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//16272
#include <bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
int a[30];
int st[30];
bool used[30];
int n , ans;
map <int,int> bin;
map <int,int> ter;
void rec( int k )
{
if( k == n + 1 )
{
ans++;
return;
}
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 );
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()
{
cin >> n;
for(int i = 1; i <= n; i++)cin >> a[i];
for(int i = 1; i <= n; i++)
{
to_bin( a[i] );
to_ter( a[i] );
}
rec(1);
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
