Submission #521784

# Submission time Handle Problem Language Result Execution time Memory
521784 2022-02-03T06:22:03 Z aadit_ambadkar Beautiful row (IZhO12_beauty) C++11
0 / 100
3000 ms 312 KB
/*
    This code belongs to Aadit Ambadkar
    Date: 2022-02-02 21:55:57
    Problem: br
*/
#include <bits/stdc++.h>
using namespace::std;

typedef long long ll;
#define F0R(i, n) for (int i = 0; i < n; i++)
#define R0F(i, n) for (int i = n-1; i >= 0; i--)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0)
#define MOD 1000000007
#define FF first
#define SS second

int bcount(int n) {
    int ans = 0;
    while (n) {
        if (n%2==1) ans++;
        n/=2;
    }
    return ans;
}

int tcount(int n) {
    int ans = 0;
    while (n) {
        if (n%3==1) ans++;
        n/=3;
    }
    return ans;
}

int n;
vector<int> arr;
vector<int> bc;
vector<int> tc;
int main() {
    fastio;
    cin >> n;
    F0R(i, n) {
        int x; cin >> x;
        arr.pb(x);
        bc.pb(bcount(x));
        tc.pb(tcount(x));
    }

    // F0R(i, n) {
    //     cout << bc[i] << " ";
    // }
    // cout << "\n";
    // F0R(i, n) {
    //     cout << tc[i] << " ";
    // }
    // cout << "\n";

    vector<int> ord;
    F0R(i, n) {
        ord.pb(i);
    }
    int ans = 0;
    do {
        bool flag = true;
        F0R(i, n-1) {
            if (bc[ord[i]]!=bc[ord[i+1]] && tc[ord[i]]!=tc[ord[i+1]]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans++;
        }
    } while (next_permutation(ord.begin(), ord.end()));
    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 216 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 25 ms 312 KB Output is correct
7 Correct 20 ms 312 KB Output is correct
8 Correct 71 ms 292 KB Output is correct
9 Correct 23 ms 204 KB Output is correct
10 Correct 56 ms 204 KB Output is correct
11 Execution timed out 3039 ms 204 KB Time limit exceeded
12 Halted 0 ms 0 KB -