# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
885761 | Zero | Beautiful row (IZhO12_beauty) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int bt(int n){
return __builtin_popcount(n);
}
int tr(int n){
int y =0;
int j = 0;
while(n){
y += pow(10,j)*(n/3);
n/=3;
j ++;
}
return y;
}
bool ok(vector<int> a){
for(int i=0; i < a.size()-1; i ++){
int b1 = bt(a[i]), t1 = tr(a[i]);
int b2 = bt(a[i+1]), t2 = tr(a[i+1]);
if(!(b1 == b2 || b1 == t2 || t1 == b2 || t1 == t2)) return 0;
}
return 1;
}
int main() {
int n; cin >> n;
vector<int> a(n);
for(auto &i : a ) cin >> i;
sort(a.begin(),a.end());
int c = 0;
do{
c += ok(a);
}while(next_permutation(a.begin(),a.end()));
cout << c;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |