結果

問題 No.1142 XOR と XOR
ユーザー kappybarkappybar
提出日時 2020-07-31 23:57:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 2,856 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 168,024 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 16:31:56
合計ジャッジ時間 4,074 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,816 KB
testcase_01 AC 7 ms
6,940 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 106 ms
6,940 KB
testcase_04 AC 71 ms
6,940 KB
testcase_05 AC 59 ms
6,940 KB
testcase_06 AC 74 ms
6,940 KB
testcase_07 AC 67 ms
6,940 KB
testcase_08 AC 91 ms
6,944 KB
testcase_09 AC 91 ms
6,944 KB
testcase_10 AC 91 ms
6,940 KB
testcase_11 AC 6 ms
6,944 KB
testcase_12 AC 6 ms
6,940 KB
testcase_13 AC 6 ms
6,944 KB
testcase_14 AC 52 ms
6,940 KB
testcase_15 AC 50 ms
6,940 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 50 ms
6,944 KB
testcase_18 AC 16 ms
6,944 KB
testcase_19 AC 73 ms
6,944 KB
testcase_20 AC 49 ms
6,940 KB
testcase_21 AC 33 ms
6,944 KB
testcase_22 AC 21 ms
6,940 KB
testcase_23 AC 68 ms
6,940 KB
testcase_24 AC 76 ms
6,944 KB
testcase_25 AC 47 ms
6,940 KB
testcase_26 AC 74 ms
6,944 KB
testcase_27 AC 60 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        while(n>0){
            if(n&1) a*=*this;
            *this*=*this;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a(n),b(m);
    vector<mint> cnta(1500),cntb(1500),alla(1500),allb(1500);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    rep(i,n-1) a[i+1] ^= a[i];
    rep(i,m-1) b[i+1] ^= b[i];
    rep(i,n) cnta[a[i]] +=1;
    rep(i,m) cntb[b[i]] +=1;
    cnta[0]+=1;
    cntb[0]+=1;

    rep(i,1500)rep(j,i+1){
        if(i==j){
            alla[0] += (cnta[i] * (cnta[j]-1)) / 2;
            allb[0] += (cntb[i] * (cntb[j]-1)) / 2;
        }
        else if((i^j)<1500){
            alla[i^j] += cnta[i] * cnta[j];
            allb[i^j] += cntb[i] * cntb[j];
        }
    }
    /*
    rep(i,n) cout << a[i] << " " ;cout << endl;
    rep(i,m) cout << b[i] << " " ;cout << endl;

    rep(i,30) cout << cnta[i] << " " ;cout << endl;
    rep(i,30) cout << cntb[i] << " " ;cout << endl;

    rep(i,30) cout << alla[i] << " " ;cout << endl;
    rep(i,30) cout << allb[i] << " " ;cout << endl;
    */

    mint ans = 0;
    rep(i,1500)rep(j,1500){
        if((i^j)==k) ans += alla[i] * allb[j];
    }
    cout << ans << endl;

    return 0;
}
0