Submission #3947427

Source Code Expand

Copy
//By Tushar Gautam
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln "\n"
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { 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) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long int  ll;
typedef long double  ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;
int a[22][22];
vv64 dp;
int lim;
ll solve(int i,int mask){
	if(i==n) return mask==lim;
	if(dp[i][mask]!=-1) return dp[i][mask];
	ll c=0;
	forn(j,n){
		if(a[i][j] && ((mask&(1<<j))==0)){
			c+=solve(i+1,mask|(1<<j));
		}
	}
	return dp[i][mask]=c%MOD;
}
int main(){
	fastio;
	cin>>n;
	forn(i,n){
		forn(j,n){
			cin>>a[i][j];
		}
	}
	lim = (1<<n)-1;
	dp.assign(n,v64(lim,-1));
	cout << solve(0,0) << ln;
	return 0;
}

Submission Info

Submission Time
Task O - Matching
User tusg25
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2510 Byte
Status
Exec Time 517 ms
Memory 360832 KB

Test Cases

Set Name Score / Max Score Test Cases
All 100 / 100 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 1 ms 256 KB
0_01 1 ms 256 KB
0_02 1 ms 256 KB
0_03 436 ms 360832 KB
1_00 1 ms 256 KB
1_01 1 ms 256 KB
1_02 131 ms 360832 KB
1_03 128 ms 360832 KB
1_04 152 ms 360832 KB
1_05 183 ms 360832 KB
1_06 365 ms 360832 KB
1_07 401 ms 360832 KB
1_08 488 ms 360832 KB
1_09 500 ms 360832 KB
1_10 508 ms 360832 KB
1_11 514 ms 360832 KB
1_12 517 ms 360832 KB