Submission #6220126


Source Code Expand

/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 22, MOD = (int)1e9 + 7;

int dp[1 << N];
int ar[N][N];
int n;

inline int add (int a, int b) { return ((a%MOD) + (b%MOD)) % MOD; };

void solve() {
   dp[0] = 0;

   for (int k = 0; k < n; ++k) {
      if (ar[1][k+1]) dp[1 << k] = 1;
   }

   for (int i = 2; i <= n; ++i) {
      for (int j = (1 << n)-1; j >= 1; --j) {
         if (__builtin_popcount(j) != i) continue;
         for (int k = 0; k < n; ++k) {
            if (ar[i][k+1] && (j & (1 << k))) dp[j] = add(dp[j], dp[j - (1 << k)]);
         }
      }
   }
   int total = dp[(1 << n)-1];
   cout << total << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n;
   for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
         cin >> ar[i][j];
   solve();

   return EXIT_SUCCESS;
}


Submission Info

Submission Time
Task O - Matching
User mr_dot_convict
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2370 Byte
Status AC
Exec Time 268 ms
Memory 10496 KiB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 17
Set Name Test Cases
All 0_00, 0_01, 0_02, 0_03, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12
Case Name Status Exec Time Memory
0_00 AC 1 ms 256 KiB
0_01 AC 1 ms 256 KiB
0_02 AC 1 ms 256 KiB
0_03 AC 148 ms 10496 KiB
1_00 AC 1 ms 256 KiB
1_01 AC 1 ms 256 KiB
1_02 AC 75 ms 256 KiB
1_03 AC 80 ms 10496 KiB
1_04 AC 96 ms 10496 KiB
1_05 AC 109 ms 10496 KiB
1_06 AC 123 ms 10496 KiB
1_07 AC 129 ms 10496 KiB
1_08 AC 193 ms 10496 KiB
1_09 AC 184 ms 10496 KiB
1_10 AC 218 ms 10496 KiB
1_11 AC 245 ms 10496 KiB
1_12 AC 268 ms 10496 KiB