Submission #691827

#TimeUsernameProblemLanguageResultExecution timeMemory
691827iskhakkutbilimBeautiful row (IZhO12_beauty)C++14
0 / 100
3058 ms300 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() int a[21], binary[21], ternary[21], used[21]; map<int, int> order; int n, answer; int ones(int x){ int s = 0; while(x > 0){ s+= (x%3==1); x/= 3; } return s; } void f(int idx, int last){ if(idx == n){ answer++; return; } for(int i = 0;i < n; i++){ if(used[i] == 0){ if(last == -1){ used[i] = 1; f(idx+1, a[i]); used[i] = 0; }else{ if(binary[i] == binary[order[last]]){ used[i] = 1; f(idx+1, a[i]); used[i] = 0; }else if(ternary[i] == ternary[order[last]]){ used[i] = 1; f(idx+1, a[i]); used[i] = 0; } } } } } main(){ cin >> n; for(int i = 0;i < n; i++){ cin >> a[i]; order[a[i]] = i; binary[i] = __builtin_popcount(a[i]); ternary[i] = ones(a[i]); } f(0, -1); cout << answer; return 0; }

Compilation message (stderr)

beauty.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...