Submission #2835851
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
/*{{{*/ //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14;
constexpr double eps = 1e-10;
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/
int main(){
int N; cin >> N;
ll x=0;
vector<ll> a(N);
rep(i,N) cin >> a[i];
rep(i,N) x ^= a[i];
set<int> st;
rep(i,N){
ll t = a[i] ^ (a[i] - 1);
st.insert(__builtin_popcount(t));
}
int ans = 0;
for(int i=30;i>=0;i--){
if((x>>i) & 1){
if(st.count(i+1)){
x ^= (1 << (i+1)) - 1;
ans++;
}
}
}
if(x != 0){
cout << -1 << endl;
}else{
cout << ans << endl;
}
}
Submission Info
Submission Time |
|
Task |
C - Cheating Nim |
User |
chakku000 |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
2228 Byte |
Status |
AC |
Exec Time |
44 ms |
Memory |
1024 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
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 |
44 ms |
1024 KB |
003.txt |
AC |
15 ms |
768 KB |
004.txt |
AC |
16 ms |
640 KB |
005.txt |
AC |
13 ms |
512 KB |
006.txt |
AC |
43 ms |
1024 KB |
007.txt |
AC |
43 ms |
1024 KB |
008.txt |
AC |
43 ms |
1024 KB |
009.txt |
AC |
43 ms |
1024 KB |
010.txt |
AC |
43 ms |
1024 KB |
011.txt |
AC |
43 ms |
1024 KB |
012.txt |
AC |
43 ms |
1024 KB |
013.txt |
AC |
44 ms |
1024 KB |
014.txt |
AC |
43 ms |
1024 KB |
015.txt |
AC |
43 ms |
1024 KB |
016.txt |
AC |
43 ms |
1024 KB |
017.txt |
AC |
43 ms |
1024 KB |
018.txt |
AC |
43 ms |
1024 KB |
019.txt |
AC |
43 ms |
1024 KB |
020.txt |
AC |
43 ms |
1024 KB |
021.txt |
AC |
5 ms |
256 KB |
022.txt |
AC |
5 ms |
384 KB |
023.txt |
AC |
41 ms |
1024 KB |
example0.txt |
AC |
1 ms |
256 KB |
example1.txt |
AC |
1 ms |
256 KB |