Submission #636764

# Submission time Handle Problem Language Result Execution time Memory
636764 2022-08-30T04:41:39 Z zeroesandones Beautiful row (IZhO12_beauty) C++17
0 / 100
1757 ms 300 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb push_back

ll getVal(int x, int t){ 
    ll cnt = 0;
    while(x) {
        ll p = x%t;
        if(p == 1) 
            ++cnt;
        x /= t;
    }

    return cnt;
}

void solve()
{
    int n;
    cin >> n;

    vi a(n);
    for(auto &i : a)
        cin >> i;

    sort(all(a));
    ll ans = 0;
    do {
        bool valid = true;
        FOR(i, 1, n) {
            if(!(getVal(a[i], 2) == getVal(a[i - 1], 2) || 
                    getVal(a[i], 3) == getVal(a[i - 1], 3))) {
                valid = false;
            }

        }
        if(valid) {
            ++ans;
            // for(auto i : a)
                // cout << i << " ";
            // cout << nl;
        }
    } while(next_permutation(all(a)));
    cout << ans << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1629 ms 296 KB Output is correct
7 Correct 1757 ms 300 KB Output is correct
8 Correct 776 ms 300 KB Output is correct
9 Incorrect 789 ms 212 KB Output isn't correct
10 Halted 0 ms 0 KB -