Submission #89292

# Submission time Handle Problem Language Result Execution time Memory
89292 2018-12-11T13:34:09 Z abil Beautiful row (IZhO12_beauty) C++14
0 / 100
3000 ms 712 KB
/**
   Solution by Abil
**/
# include <bits/stdc++.h>

////////////////////////

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);

vector<int > v;
int arr[N];
int f(int x){
   int cnt = 0;
   while(x){
    if(x % 3 == 1){
      cnt++;
    }
    x = x / 3;
   }
   return cnt;
}
main()
{
   int n, x;
   cin >> n;
   for(int i = 1;i <= n; i++){
    cin >> arr[i];
    v.pb(i);
   }
   sort(all(v));
   int ans = 0;
   do{
    bool f1 = true;
    for(int i = 0;i < sz(v) - 1; i++){
      if((__builtin_popcount(arr[v[i]])) != (__builtin_popcount(arr[v[i + 1]])) && (f(arr[v[i]]) != f(arr[v[i + 1]]))){
        f1 = false;
        break;
      }
    }
    if(f1){
      ans++;
    }
   }
   while(next_permutation(all(v)));
   cout << ans;
}

Compilation message

beauty.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
beauty.cpp: In function 'int main()':
beauty.cpp:45:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < sz(v) - 1; i++){
                   ~~^~~~~~~~~~~
beauty.cpp:35:11: warning: unused variable 'x' [-Wunused-variable]
    int n, x;
           ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 239 ms 624 KB Output is correct
7 Correct 182 ms 624 KB Output is correct
8 Correct 322 ms 704 KB Output is correct
9 Correct 203 ms 712 KB Output is correct
10 Correct 643 ms 712 KB Output is correct
11 Execution timed out 3067 ms 712 KB Time limit exceeded
12 Halted 0 ms 0 KB -