Submission #1001076


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define P 1000000007
#define N 310
int n;
int C[N][N];
int P2[N];

void gcd(int a,int b,int &x,int &y) {
  if(b==0){x=1,y=0;return;}
  gcd(b,a%b,y,x),y-=a/b*x;
}
int inv(int n) {
  int x,y;gcd(n,P,x,y);
  if(x<0)x+=P;return x;
}

ll f[N][N];

ll ff(int m, int r) {
	if (r < 0) return 0;
	if (r > m) return 0;
	if (m == 0) return 1;
	if (f[m][r] != -1) return f[m][r];
	ll S = 0;
	// Case 1: last is in
	
	ll T1 = 0;
	T1 = ff(m-1, r);
	T1 = (ll)T1 * P2[r]%P;
	
	// Case 2: last is not in
	ll T2 = 0;
	T2 = ff(m-1,r-1);
	ll C = P2[n] - P2[r-1];
	if (C < 0) C += P;
	T2 = (ll)T2 * C %P;
	//cout << m << " " << r << " " << T1 << " " << T2 << endl;
	
	S = (T1 + T2)%P;
	
	f[m][r] = S;
	return S;
}

ll gg(int n, int m) {
	if (m > n) return 0;
	ll S = 1;
	for (int i = 0; i < m; i ++) {
		ll T = P2[n] - P2[i];
		if (T < 0) T += P;
		S = (ll)S*T%P;
	}
	for (int i = 0; i < m; i ++) {
		ll T = P2[m] - P2[i];
		if (T < 0) T += P;
		S = (ll)S*inv(T)%P;
	}
	return S;
}

int main () {
	P2[0] = 1;
	for (int i = 1; i < N; i ++) P2[i] = P2[i-1]*2%P;
	cin >> n;
	for (int i = 0; i < n; i ++)
		for (int j = 0; j < n; j ++)
			cin >> C[i][j];
	int nw = 0;
	for (int i = 0; i < n; i ++) {
		for (int j = i; j < n; j ++) {
			if (C[j][i]) {
				for (int k = 0; k < n; k ++)
					swap(C[nw][k], C[j][k]);
				break;
			}
		}
		if (!C[nw][i]) continue;
		for (int j = nw+1; j < n; j ++)
			if (C[j][i]) {
				for (int k = 0; k < n; k ++)
					C[j][k] ^= C[nw][k];
			}
		nw++;
	}
	//cout << nw << endl;
	for (int i = 0; i <= n; i ++)
		for (int j = 0; j <= n; j ++) f[i][j] = -1;
	ll S = 0;
	for (int rk = 0; rk <= n; rk ++) {
		ll T = ff(n, rk); // #mat with rk r
		ll T1 = gg(n, nw); // #nw subsp in n
		ll T2 = gg(rk, nw); // #nw subsp in rk
		ll TP = (ll) T2 * inv(T1)%P; // prob contain subsp
		T = (ll)T*TP%P;
		for (int i = 0; i < n; i ++) { // fixed
			T = (ll)T*P2[n-rk]%P;
		}
		/*
		for (int i = nw; i < n; i ++) { // any
			T = (ll)T*P2[n]%P;
		}
		*/
		(S += T) %= P;
	}
	cout << S << endl;
	return 0;
}

Submission Info

Submission Time
Task H - AB=C Problem
User sevenkplus
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 2291 Byte
Status AC
Exec Time 46 ms
Memory 1408 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 2
AC × 42
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 2 ms 256 KB
001.txt AC 2 ms 256 KB
002.txt AC 2 ms 256 KB
003.txt AC 2 ms 256 KB
004.txt AC 2 ms 256 KB
005.txt AC 2 ms 256 KB
006.txt AC 2 ms 256 KB
007.txt AC 2 ms 256 KB
008.txt AC 2 ms 256 KB
009.txt AC 2 ms 256 KB
010.txt AC 2 ms 256 KB
011.txt AC 2 ms 256 KB
012.txt AC 2 ms 256 KB
013.txt AC 2 ms 256 KB
014.txt AC 9 ms 640 KB
015.txt AC 8 ms 640 KB
016.txt AC 5 ms 512 KB
017.txt AC 13 ms 1024 KB
018.txt AC 4 ms 512 KB
019.txt AC 2 ms 256 KB
020.txt AC 12 ms 768 KB
021.txt AC 41 ms 1280 KB
022.txt AC 4 ms 512 KB
023.txt AC 27 ms 1280 KB
024.txt AC 46 ms 1408 KB
025.txt AC 41 ms 1408 KB
026.txt AC 43 ms 1408 KB
027.txt AC 37 ms 1408 KB
028.txt AC 25 ms 1408 KB
029.txt AC 42 ms 1408 KB
030.txt AC 43 ms 1408 KB
031.txt AC 39 ms 1408 KB
032.txt AC 24 ms 1408 KB
033.txt AC 45 ms 1408 KB
034.txt AC 24 ms 1408 KB
035.txt AC 15 ms 1152 KB
036.txt AC 46 ms 1408 KB
037.txt AC 39 ms 1280 KB
038.txt AC 24 ms 1408 KB
039.txt AC 45 ms 1280 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 2 ms 256 KB