Submission #3920055


Source Code Expand

#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


int solve(int N, vi& a) {
    int ax = 0;
    vi mv(32, 0);
    rep(i,N) {
        ax ^= a[i];
        int x = a[i] ^ (a[i] - 1);
        int popcnt = __builtin_popcount(x);
        mv[popcnt - 1] = x;
    }
    if (ax == 0) return 0;

    int n = 32 - __builtin_clz(ax), cnt = 0;
    for (int i=n-1; i>=0; --i) {
        if (ax & (1 << i)) {
            if (!mv[i]) return -1;
            ax ^= mv[i];
            ++cnt;
        } else {
            continue;
        }
    }
    return cnt;
}

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

Submission Info

Submission Time
Task C - Cheating Nim
User naoya_t
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2079 Byte
Status AC
Exec Time 14 ms
Memory 640 KB

Compile Error

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
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, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 256 KB
001.txt AC 1 ms 256 KB
002.txt AC 14 ms 640 KB
003.txt AC 7 ms 512 KB
004.txt AC 6 ms 384 KB
005.txt AC 5 ms 384 KB
006.txt AC 14 ms 640 KB
007.txt AC 13 ms 640 KB
008.txt AC 13 ms 640 KB
009.txt AC 13 ms 640 KB
010.txt AC 13 ms 640 KB
011.txt AC 13 ms 640 KB
012.txt AC 13 ms 640 KB
013.txt AC 13 ms 640 KB
014.txt AC 13 ms 640 KB
015.txt AC 13 ms 640 KB
016.txt AC 13 ms 640 KB
017.txt AC 13 ms 640 KB
018.txt AC 13 ms 640 KB
019.txt AC 13 ms 640 KB
020.txt AC 14 ms 640 KB
021.txt AC 2 ms 256 KB
022.txt AC 2 ms 256 KB
023.txt AC 13 ms 640 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB