結果

問題 No.1210 XOR Grid
ユーザー Kite_kumaKite_kuma
提出日時 2020-08-30 14:18:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,086 ms / 2,000 ms
コード長 13,817 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 178,792 KB
実行使用メモリ 9,484 KB
最終ジャッジ日時 2023-08-09 12:22:08
合計ジャッジ時間 13,707 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 104 ms
6,244 KB
testcase_26 AC 45 ms
6,140 KB
testcase_27 AC 45 ms
6,244 KB
testcase_28 AC 117 ms
6,148 KB
testcase_29 AC 39 ms
4,996 KB
testcase_30 AC 32 ms
4,948 KB
testcase_31 AC 39 ms
4,992 KB
testcase_32 AC 39 ms
4,980 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 75 ms
6,152 KB
testcase_37 AC 19 ms
6,208 KB
testcase_38 AC 19 ms
6,156 KB
testcase_39 AC 53 ms
6,140 KB
testcase_40 AC 905 ms
9,416 KB
testcase_41 AC 981 ms
9,484 KB
testcase_42 AC 1,071 ms
9,352 KB
testcase_43 AC 877 ms
9,416 KB
testcase_44 AC 1,029 ms
9,468 KB
testcase_45 AC 1,077 ms
9,412 KB
testcase_46 AC 1,086 ms
9,412 KB
testcase_47 AC 46 ms
9,396 KB
testcase_48 AC 44 ms
9,408 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 380 ms
9,384 KB
testcase_51 AC 76 ms
6,580 KB
testcase_52 AC 67 ms
6,528 KB
testcase_53 AC 77 ms
6,744 KB
testcase_54 AC 45 ms
9,380 KB
testcase_55 AC 49 ms
6,744 KB
testcase_56 AC 39 ms
5,180 KB
testcase_57 AC 42 ms
5,936 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#pragma region macros_and_aliases

#define rep(i, n) for(long long i = 0; i < (n); i++)
#define rrep(i, n) for(long long i = (n)-1; i > -1; i--)
#define Rep(i, m, n) for(long long i = (m); i < (n); i++)
#define rRep(i, m, n) for(long long i = (n)-1; i >= (m); i--)
#define REP(i, m, n, p) for(long long i = m; i < n; i += p)
#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bcnt(n) __builtin_popcountll(n)
#define endk endl
#define ednl endl
#define enld endl

using ll = long long;
using ld = long double;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using qll = queue<long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
template <class T = ll>
using V = vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
//昇順pq(小さい方から取り出す)
template <class T = ll>
using pqup = priority_queue<T, vector<T>, greater<T>>;
//降順pq(大きい方から取り出す)
template <class T = ll>
using pqdn = priority_queue<T>;

#pragma region debug
#define debug(var)                  \
	do {                            \
		std::cout << #var << " : "; \
		view(var);                  \
	} while(0)

template <typename T>
void view(T e) {
	std::cout << e << "\n";
}
template <typename T>
void view(const std::vector<T> &v) {
	for(const auto &e : v) {
		std::cout << e << " ";
	}
	std::cout << "\n";
}
template <typename T>
void view(const std::set<T> &s) {
	for(auto &t : s) {
		std::cout << t << " ";
	}
	std::cout << "\n";
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	std::cout << "\n";
	for(const auto &v : vv) {
		view(v);
	}
}
template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	std::cout << "\n";
	for(const auto &c : v) {
		std::cout << c.first << " " << c.second << "\n";
	}
}
template <typename T, typename U>
void view(const std::map<T, U> &m) {
	std::cout << "\n";
	for(auto &t : m) {
		std::cout << t.first << " " << t.second << "\n";
	}
}

#pragma endregion

#pragma region input
#define VEC(type, name, size) \
	vector<type> name(size);  \
	IN(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	IN(name)
#define INT(...)     \
	int __VA_ARGS__; \
	IN(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	IN(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	IN(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	IN(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	IN(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	IN(__VA_ARGS__)

template <class T>
void scan(T &a) {
	cin >> a;
}
template <class T>
void scan(vector<T> &a) {
	for(auto &i : a) scan(i);
}
template <class T, class L>
void scan(pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}
void IN() {}
template <class Head, class... Tail>
void IN(Head &head, Tail &... tail) {
	scan(head);
	IN(tail...);
}
template <class T>
inline void print(T x) {
	cout << x << '\n';
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}
#pragma endregion

#pragma endregion

#pragma region constants

long long const limLL = 9223372036854775807;  // POW(2,63)-1 ~ 9.22e18
long long const dekai = 3e16;
const long double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int mod = 1000000007;
// const int mod = 998244353;
#pragma endregion

#pragma region basic_procedure

template <class T>
inline bool isin(T x, T lef, T rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool f = 1) { cout << (f ? "Yes" : "No") << "\n"; }
void No() { cout << "No\n"; }
void YES(bool f = 1) { cout << (f ? "YES" : "NO") << "\n"; }
void NO() { cout << "NO\n"; }
void err() {
	cout << -1 << "\n";
	exit(0);
}

vector<long long> vin(long long n) {  //整数n個の入力を受け取ってベクトルに突っ込んで返す
	vector<long long> v(n);
	for(long long i = 0; i < n; i++) {
		cin >> v[i];
	}
	return v;
}

//ベクトルの出力(検証済)
// vectorの中身を出力する 答えの出力に利用可能
template <class T>
void vout(vector<T> &v, bool tate = 0) {
	if(v.size() > 0) {
		for(auto it = v.begin(); it < v.end(); it++) {
			cout << *it;
			if(it != v.end() - 1) {
				if(tate)
					cout << endl;
				else
					cout << " ";
			}
		}
	}
	cout << endl;
}

template <class T>
void add(vector<T> &v, T val) {	 //ベクトルの各要素に加算
	for(auto &a : v) a += val;
	return;
}

// vectorの中身を数える map<要素,個数>を返す
template <class T>
map<T, long long> cntv(vector<T> v) {
	map<T, long long> m;
	for(auto &g : v) {
		if(m.count(g))
			m[g]++;
		else
			m[g] = 1;
	}
	return m;
}

//配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1,  0}にする
template <class T>
vector<long long> press(vector<T> &v) {
	long long n = v.size();
	vector<long long> w(n);
	map<T, long long> m;
	for(T &p : v) m[p] = 0;
	long long i = 0;
	for(auto &p : m) {
		p.second = i;
		i++;
	}
	for(long long i = 0; i < n; i++) w.at(i) = m[v.at(i)];
	return w;
}

template <class T>
T divup(T a, T b) {
	//端数繰りあがり割り算
	assert(b != 0);
	T x = abs(a);
	T y = abs(b);
	T z = (x + y - 1) / y;
	if((a < 0 && b > 0) || (a > 0 && b < 0))
		return -z;
	else if(a == 0)
		return 0;
	else
		return z;
}

long long POW(long long a, long long n) {
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}

template <class T>
int sgn(T x) {	//符号関数
	if(x < 0) return -1;
	if(x == 0) return 0;
	return 1;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	if(mod == 1) return 0LL;
	long long res = 1;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a * x % mod == __gcd(a,mod)なるxを返す
// a が modの倍数でないことが条件
long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

vvll comb(100, vll(100, -1));
long long com(long long n, long long k) {  //普通の二項計数(overflowに注意)
	assert(n < 100 && k < 100);
	if(n < k || k < 0 || n < 0) return 0;
	if(comb[n][k] != -1) return comb[n][k];
	ll res;
	if(n - k < k)
		res = com(n, n - k);
	else if(k == 0)
		res = 1;
	else
		res = com(n - 1, k - 1) + com(n - 1, k);
	comb[n][k] = res;
	return res;
}

// nCk modを求める
const ll MAX = 5100000;
// この値は求める二項計数の値に応じて変える
// MAX=3*10^7のとき1900msほど、ほぼ比例
// MAX=5*10^6程度ならそれほど気にしなくてよい(300ms程)
long long fac[MAX], finv[MAX], inv[MAX];

void cominit() {
	// テーブルを作る前処理
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long commod(ll n, ll k) {	// 二項係数計算
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long pmod(ll n, ll k) {  //順列計算
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * finv[n - k] % mod;
}
long long hmod(ll n, ll k) {  // nHk計算
	// n個の区別しないoを区別するk個の箱に入れる方法の総数
	//(n+k-1)C(k-1)と等しい
	return commod(n + k - 1, n);
}
#pragma endregion

template <class T = long long, class U = long long>
class LazyST {
	// private:
   public:
	int n;
	int height = -1;	  //木の高さ
	vector<T> data;		  // monoid
	vector<U> lazy;		  // operator
	T unit_data;		  // monoid単位元
	U unit_lazy;		  // operator単位元
	function<T(T, T)> f;  // monoid同士の演算
	function<T(T, U)> g;  // monoidとoperatorとの演算
	function<U(U, U)> h;  // operator同士の演算
	void propagate(int lef, int rig) {
		// 遅延させていた作用素を上から伝播させる [lef,rig)に有効な範囲で
		lef += n;
		rig += n - 1;  //閉区間にする
		for(int i = height; i > 0; i--) {
			int l = lef >> i;
			int r = rig >> i;
			lazy[l << 1] = h(lazy[l << 1], lazy[l]);
			lazy[l << 1 | 1] = h(lazy[l << 1 | 1], lazy[l]);
			data[l] = g(data[l], lazy[l]);
			lazy[l] = unit_lazy;
			lazy[r << 1] = h(lazy[r << 1], lazy[r]);
			lazy[r << 1 | 1] = h(lazy[r << 1 | 1], lazy[r]);
			data[r] = g(data[r], lazy[r]);
			lazy[r] = unit_lazy;
		}
	}

	// 全て同じmonoid = init_dataで初期化
	LazyST(int _n, function<T(T, T)> ope_data_data, function<T(T, U)> ope_data_lazy, function<U(U, U)> ope_lazy_lazy, T _unit_data,
		   U _unit_lazy, T init_data)
		: n(_n), f(ope_data_data), g(ope_data_lazy), h(ope_lazy_lazy), unit_data(_unit_data), unit_lazy(_unit_lazy) {
		data.assign(n * 2, unit_data);
		for(int i = 0; i < n; i++) {
			data[i + n] = init_data;
		}
		for(int i = n - 1; i > -1; i--) {
			data[i] = f(data[i << 1], data[i << 1 | 1]);
		}
		lazy.assign(n * 2, unit_lazy);
		for(int i = 1; i <= n; i *= 2) height++;
	}
	// 初期化配列をvectorで渡す
	LazyST(int _n, function<T(T, T)> ope_data_data, function<T(T, U)> ope_data_lazy, function<U(U, U)> ope_lazy_lazy, T _unit_data,
		   U _unit_lazy, vector<T> raw_data)
		: n(_n), f(ope_data_data), g(ope_data_lazy), h(ope_lazy_lazy), unit_data(_unit_data), unit_lazy(_unit_lazy) {
		data.assign(n * 2, unit_data);
		for(int i = 0; i < n; i++) {
			data[i + n] = raw_data[i];
		}
		for(int i = n - 1; i > -1; i--) {
			data[i] = f(data[i << 1], data[i << 1 | 1]);
		}
		lazy.assign(n * 2, unit_lazy);
		for(int i = 1; i <= n; i *= 2) height++;
	}

	void update(int lef, int rig, U _operator) {  //[lef,rig)にopeを作用させる
		propagate(lef, rig);
		lef += n;
		rig += n;  //半開区間にする 下から上にdataを更新
		int L0 = lef / (lef & -lef);
		int R0 = rig / (rig & -rig);
		while(lef < rig) {
			if(lef & 1) {
				lazy[lef] = h(lazy[lef], _operator);
				lef++;
			}
			if(rig & 1) {
				lazy[rig - 1] = h(lazy[rig - 1], _operator);
				rig--;
			}
			lef >>= 1;
			rig >>= 1;
		}
		lef = L0;
		rig = R0;
		while(lef > 1) {
			lef >>= 1;
			data[lef] = f(g(data[lef << 1], lazy[lef << 1]), g(data[lef << 1 | 1], lazy[lef << 1 | 1]));
			lazy[lef] = unit_lazy;
		}
		while(rig > 1) {
			rig >>= 1;
			data[rig] = f(g(data[rig << 1], lazy[rig << 1]), g(data[rig << 1 | 1], lazy[rig << 1 | 1]));
			lazy[rig] = unit_lazy;
		}
	}

	T get(int lef, int rig) {  //区間の値取得
		propagate(lef, rig);
		T a = unit_data, b = unit_data;
		lef += n;
		rig += n;
		while(lef < rig) {
			if(lef & 1) a = f(a, g(data[lef], lazy[lef]));
			if(rig & 1) b = f(g(data[rig - 1], lazy[rig - 1]), b);
			(lef += 1) >>= 1;
			rig >>= 1;
		}
		return f(a, b);
	}
};
struct Fast_Factorization {
	int n;	//最大のn
	vector<int> v;

	Fast_Factorization(int _n) : n(_n), v(_n + 1) {
		v[0] = v[1] = 1;
		for(int i = 2; i <= n; i++) {
			if(v[i]) continue;
			int k = i;
			while(k <= n) {
				if(!v[k]) v[k] = i;
				k += i;
			}
		}
	}

	vector<int> factor(int num) {  // 素因数分解 vector{素因数、素因数、...}(重複有り)
		vector<int> ret;
		while(num > 1) ret.push_back(v[num]), num /= v[num];
		return ret;
	}

	map<int, int> facmap(int num) {	 //素因数分解 map<素因数,個数>
		map<int, int> ret;
		while(num > 1) {
			int cnt = 0, div = v[num];
			while(num % div == 0) num /= div, cnt++;
			ret[div] = cnt;
		}
		return ret;
	}
};
struct mint {
	long long x;
	mint(long long x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint &operator+=(const mint a) {
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint &operator-=(const mint a) {
		if((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint &operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(long long t) const {
		if(!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if(t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint &operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	// cout << fixed << setprecision(15);

	INT(n, m, x);
	vll a = vin(n), b = vin(m);

	ll h = 0;
	foa(t, a) h ^= t;
	foa(t, b) h ^= t;
	if(h) {
		cout << 0 << endl;
		exit(0);
	}

	long long ans = 1;

	rep(i, x) {
		vll h(n), w(m);
		rep(j, n) { h[j] = 1 & (a[j] >> i); }
		// rep(j, m) { w[j] = 1 & (b[j] >> i); }
		rep(j, n - 1) {
			(ans *= modpow(2, m-1, mod)) %=mod;
			//ans /= 2;
		}
	}
	cout << ans << endl;
}
0