Submission #106206

# Submission time Handle Problem Language Result Execution time Memory
106206 2019-04-17T10:34:30 Z Hideo Beautiful row (IZhO12_beauty) C++14
0 / 100
16 ms 2944 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, int >
#define pii pair < int, pi >
#define vii vector < pi >

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int b[20], t[20];
int n;

ll dp[(1 << 20)][20];
ll ans;

int bin (int x, int c = 0){
    if (x % 2 == 1)
        c++;
    if (!x)
        return c;
    bin(x / 2, c);
}

int ter (int x, int c = 0){
    if (x % 3 == 1)
        c++;
    if (!x)
        return c;
    ter(x / 3, c);
}

main(){
    cin >> n;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        b[i] = bin(a);
        t[i] = ter(a);
    }
    for (int i = 0; i < n; i++)
        dp[(1 << i)][i] = 1;

    for (int val = 2; val <= n; val++){
        for (int mask = 1; mask < (1 << n); mask++){
            int cnt = 0;
            for (int sub = 0; sub < n; sub++)
                if (mask & (1 << sub))
                    cnt++;
            if (cnt != val)
                continue;
            for (int sub = 0; sub < n; sub++){
                if (mask & (1 << sub)){
                    int submask = (mask ^ (1 << sub));
                    for (int last = 0; last < n; last++)
                        if (last != sub && submask & (1 << last) && (b[last] == b[sub] || t[last] == t[sub]))
                            dp[mask][sub] += dp[submask][last];
                    dp[mask][sub] %= mod;
                }
            }
        }
    }
    int mask = 0;
    for (int i = 0; i < n; i++)
        mask += (1 << i);
    for (int last = 0; last < n; last++)
        ans += dp[mask][last];
    cout << ans % mod;
}

Compilation message

beauty.cpp:40:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
beauty.cpp: In function 'int bin(int, int)':
beauty.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
beauty.cpp: In function 'int ter(int, int)':
beauty.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 4 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Incorrect 16 ms 2944 KB Output isn't correct
12 Halted 0 ms 0 KB -