結果

問題 No.1142 XOR と XOR
ユーザー iqueue02
提出日時 2020-08-01 00:12:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 2,047 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 198,788 KB
最終ジャッジ日時 2025-01-12 12:02:09
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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(ll 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;}
};
int main() {
  int n, m, k;
  cin >> n >> m >> k;

  vector<int> a(n), b(m);

  rep(i,n) cin >> a[i];
  rep(j,m) cin >> b[j];

  vector<int> a_cum(n + 1, 0), b_cum(m + 1, 0);

  for (int i = 0; i < n; i++) a_cum[i + 1] = a_cum[i] ^ a[i];
  for (int i = 0; i < m; i++) b_cum[i + 1] = b_cum[i] ^ b[i];

  vector<mint> a_cnt(1 << 10, 0), b_cnt(1 << 10, 0); 

  for (int i = 0; i <= n; i++) a_cnt[a_cum[i]] += 1;
  for (int j = 0; j <= m; j++) b_cnt[b_cum[j]] += 1;

  vector<mint> dp1(1 << 10, 0), dp2(1 << 10, 0);

  for (int i = 0; i < (1 << 10); i++) {
    for (int j = 0; j < (1 << 10); j++) {
      dp1[i ^ j] += a_cnt[i] * (a_cnt[j] - (i == j ? 1 : 0));
      dp2[i ^ j] += b_cnt[i] * (b_cnt[j] - (i == j ? 1 : 0));
    }
  } 

  mint res = 0;

  for (int i = 0; i < (1 << 10); i++) dp1[i] /= 2, dp2[i] /= 2;

  for (int i = 0; i < (1 << 10); i++) res += dp1[i] * dp2[i ^ k];

  cout << res.x << endl;

  return 0;
} 
0