Submission #3915466

Source Code Expand

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

class UnionFind {
 public:
  vector<int> data;
  int count;
 public:
  UnionFind(int size) : data(size, -1), count(size) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
      --count;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

#define MAXSIZE 131072

ll solve(int N, int K, vi& a) {
    int bits = 0;
    rep(i,N) bits |= a[i];
    if ((bits & K) != K) return 0;

    bitset<MAXSIZE> bs;
    bs.reset();
    bs.set(0, true);
    rep(i,N){
        int ai = a[i];
        if (bs.test(ai)) continue;
        rep(j, MAXSIZE) {
            if (bs.test(j)) bs.set(j ^ ai);
        }
    }
    if (!bs.test(K)) return 0;
    int denom = bs.count();
    return DIV(POW(2,N), denom);
}

int main() {
    int N,K; scanf("%d%d", &N, &K);
    vi a(N); rep(i,N) scanf("%d", &a[i]);
    cout << solve(N,K,a) << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Limited Xor Subset
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 3377 Byte
Status
Exec Time 9 ms
Memory 640 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:103:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int N,K; scanf("%d%d", &N, &K);
                                   ^
./Main.cpp:104:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     vi a(N); rep(i,N) scanf("%d", &a[i]);
                                         ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 500 / 500 sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_2.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_3.txt, subtask_1_30.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
Case Name Status Exec Time Memory
sample_01.txt 2 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 2 ms 256 KB
subtask_1_1.txt 3 ms 256 KB
subtask_1_10.txt 3 ms 256 KB
subtask_1_11.txt 3 ms 256 KB
subtask_1_12.txt 3 ms 256 KB
subtask_1_13.txt 3 ms 256 KB
subtask_1_14.txt 3 ms 256 KB
subtask_1_15.txt 3 ms 256 KB
subtask_1_16.txt 2 ms 256 KB
subtask_1_17.txt 1 ms 256 KB
subtask_1_18.txt 7 ms 512 KB
subtask_1_19.txt 5 ms 384 KB
subtask_1_2.txt 3 ms 256 KB
subtask_1_20.txt 2 ms 256 KB
subtask_1_21.txt 2 ms 256 KB
subtask_1_22.txt 1 ms 256 KB
subtask_1_23.txt 1 ms 256 KB
subtask_1_24.txt 1 ms 256 KB
subtask_1_25.txt 9 ms 640 KB
subtask_1_26.txt 1 ms 256 KB
subtask_1_27.txt 1 ms 256 KB
subtask_1_28.txt 2 ms 256 KB
subtask_1_29.txt 1 ms 256 KB
subtask_1_3.txt 3 ms 256 KB
subtask_1_30.txt 2 ms 256 KB
subtask_1_4.txt 3 ms 256 KB
subtask_1_5.txt 1 ms 256 KB
subtask_1_6.txt 5 ms 384 KB
subtask_1_7.txt 3 ms 256 KB
subtask_1_8.txt 2 ms 256 KB
subtask_1_9.txt 2 ms 256 KB