답안 #944487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944487 2024-03-12T19:01:53 Z Zena_Hossam 아름다운 순열 (IZhO12_beauty) C++14
0 / 100
3000 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
#define fi ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll double
#define ll long long
//#define ll1 long long
#define F first
#define S second
#define sz size()
#define all(s) s.begin(),s.end()
#define all1(s) s.rbegin(),s.rend()
ll c=0,n;vector<vector<ll>>s;
void solve(vector<ll>v,ll k,ll o){vector<ll>e=v;e[k]=1;//cout<<k<<" ";
if(o==n-1){
    c++;return;

}
for(ll i=0;i<s[k].sz;i++){

    if(e[s[k][i]])continue;
    solve(e,s[k][i],o+1);
}return;
}
int main()
{
   // freopen("measurement.in","r",stdin);freopen("measurement.out","w",stdout);
    ll T=1;
    //cin>>T;ll oo=0;
    while(T--)
    {
       cin>>n;
       ll arr[n];s.resize(n+5);
       for(ll i=0;i<n;i++){
        cin>>arr[i];
       }map<ll,ll>m,d;
       for(ll i=0;i<n;i++){
            ll a=arr[i];ll p=0;
            while(a!=0){
                if(a%2==1)p++;
                a/=2;
            }
            m[i]=p;
            ll b=arr[i];ll pp=0;
            while(b!=0){
                if(b%3==1)pp++;
                b/=3;
            }
            d[i]=pp;
       }
       for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){if(i==j)continue;
            if(m[i]==m[j]){s[i].push_back(j);//cout<<i<<" "<<j<<"k\n";
            }
            else if(d[i]==d[j]){s[i].push_back(j);//cout<<i<<" "<<j<<"k\n";
            }
        }
       }vector<ll>r(n+9,0);
       for(ll i=0;i<n;i++){
       solve(r,i,0);//cout<<"\n";
       }cout<<c;
    }
}

Compilation message

beauty.cpp:5: warning: "ll" redefined
    5 | #define ll long long
      | 
beauty.cpp:4: note: this is the location of the previous definition
    4 | #define ll double
      | 
beauty.cpp: In function 'void solve(std::vector<long long int>, long long int, long long int)':
beauty.cpp:18:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 | for(ll i=0;i<s[k].sz;i++){
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 444 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 509 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 222 ms 416 KB Output is correct
11 Execution timed out 3036 ms 344 KB Time limit exceeded
12 Halted 0 ms 0 KB -