Submission #1005396


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }


template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
};
typedef ModInt<1000000007> mint;
template<int... Sizes>
struct MultidimensionalIndex;
template<>
struct MultidimensionalIndex<> {
	MultidimensionalIndex() {}
	int getTotalSize() const { return 1; }
	int getIndexAcc(int acc) const { return acc; }
};
template<int Head, int... Tail>
struct MultidimensionalIndex<Head, Tail...> : MultidimensionalIndex<Tail...> {
	using Base = MultidimensionalIndex<Tail...>;
	enum { size = Head };
	template<typename... TailT>
	MultidimensionalIndex(TailT... tail) : Base(tail...) {}
	int getTotalSize() const { return size * Base::getTotalSize(); }
	template<typename... TailT>
	int getIndexAcc(int acc, int head, TailT... tail) const { return Base::getIndexAcc(acc * size + head, tail...); }
};
template<int... Tail>
struct MultidimensionalIndex<0, Tail...> : MultidimensionalIndex<Tail...> {
	using Base = MultidimensionalIndex<Tail...>;
	const int size;
	template<typename... TailT>
	MultidimensionalIndex(int head, TailT... tail) : size(head), MultidimensionalIndex<Tail...>(tail...) {}
	int getTotalSize() const { return size * Base::getTotalSize(); }
	template<typename... TailT>
	int getIndexAcc(int acc, int head, TailT... tail) const { return Base::getIndexAcc(acc * size + head, tail...); }
};

template<typename Val, int... Sizes>
struct DP : MultidimensionalIndex<Sizes...> {
	using Base = MultidimensionalIndex<Sizes...>;
	std::vector<Val> dp;
	template<typename... SizesT>
	DP(SizesT... sizes) : Base(sizes...) {}
	void init(Val val) { dp.assign(Base::getTotalSize(), val); }
	void init() { dp.assign(Base::getTotalSize(), Val()); }
	template<typename... SizesT>
	Val &operator()(SizesT... indices) { return dp[Base::getIndexAcc(0, indices...)]; }
	template<typename... SizesT>
	Val operator()(SizesT... indices) const { return dp[Base::getIndexAcc(0, indices...)]; }
	void swap(DP &that) { dp.swap(that.dp); }
};

typedef bitset<300> BitSet;
int getRank(vector<BitSet> v, int B) {
	int n = (int)v.size(), rank = 0, used = 0;
	for(int j = B - 1; j >= 0; j --) {
		int i = used;
		while(i < n && !v[i][j]) i ++;
		if(i < n) {
			BitSet x = v[i];
			swap(v[i], v[used ++]);
			++ rank;
			for(i = used; i < n; i ++)
				if(v[i][j])
					v[i] ^= x;
		}
	}
	return rank;
}

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<BitSet> C(N);
		for(int i = 0; i < N; ++ i) {
			BitSet row;
			rep(j, N) {
				int c;
				scanf("%d", &c);
				row[j] = c != 0;
			}
			C[i] = row;
		}
		int rank = getRank(C, N);
		vector<mint> two(N * N + 1);
		two[0] = 1;
		rer(n, 1, N * N)
			two[n] = two[n - 1] + two[n - 1];
		DP<mint, 0, 0> dp(N + 1, rank + 1), ndp = dp;
		ndp.init();
		ndp(0, 0) = 1;
		rep(i, N) {
			dp.swap(ndp);
			ndp.init();
			rer(j, 0, i) rer(k, 0, min(j, rank)) {
				mint x = dp(j, k);
				if(x.x == 0) continue;
				ndp(j, k) += x * two[j];
				ndp(j + 1, k) += x * (two[N] - two[j + rank - k]);
				if(k < rank)
					ndp(j + 1, k + 1) += x * (two[j + rank - k] - two[j]);
			}
		}
		mint ans;
		rer(j, rank, N)
			ans += ndp(j, rank) * two[N * (N - j)];
		printf("%d\n", ans.get());
	}
	return 0;
}

Submission Info

Submission Time
Task H - AB=C Problem
User anta
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 4569 Byte
Status AC
Exec Time 81 ms
Memory 1280 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:100:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &c);
                    ^

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 3 ms 256 KB
001.txt AC 3 ms 256 KB
002.txt AC 3 ms 256 KB
003.txt AC 3 ms 256 KB
004.txt AC 3 ms 256 KB
005.txt AC 3 ms 256 KB
006.txt AC 3 ms 256 KB
007.txt AC 2 ms 256 KB
008.txt AC 3 ms 256 KB
009.txt AC 2 ms 256 KB
010.txt AC 2 ms 256 KB
011.txt AC 3 ms 256 KB
012.txt AC 3 ms 256 KB
013.txt AC 3 ms 256 KB
014.txt AC 6 ms 384 KB
015.txt AC 7 ms 384 KB
016.txt AC 4 ms 256 KB
017.txt AC 7 ms 384 KB
018.txt AC 3 ms 256 KB
019.txt AC 3 ms 256 KB
020.txt AC 14 ms 384 KB
021.txt AC 78 ms 1024 KB
022.txt AC 3 ms 256 KB
023.txt AC 40 ms 640 KB
024.txt AC 40 ms 1280 KB
025.txt AC 81 ms 1024 KB
026.txt AC 77 ms 1152 KB
027.txt AC 75 ms 896 KB
028.txt AC 23 ms 640 KB
029.txt AC 81 ms 1024 KB
030.txt AC 79 ms 1024 KB
031.txt AC 80 ms 896 KB
032.txt AC 12 ms 640 KB
033.txt AC 69 ms 1152 KB
034.txt AC 10 ms 640 KB
035.txt AC 7 ms 512 KB
036.txt AC 30 ms 1280 KB
037.txt AC 25 ms 1152 KB
038.txt AC 15 ms 640 KB
039.txt AC 32 ms 1280 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 3 ms 256 KB