Submission #2708200


Source Code Expand

int check[30];

int c, n, a;

int main() {

  for (int bit = 29; bit >= 0; bit--) {
    check[bit] = 0;
  }

  scanf("%d", &n);
  int xor_sum = 0;
  for (int i = 0; i < n; i++) {
    while (1) {
      c = getchar_unlocked();
      if ('0' <= c && c <= '9')
        a = a * 10 + c - '0';
      else
        break;
    }
    xor_sum ^= a;
    a = a ^ (a - 1);

    switch (a) {
    case 1073741823:
      check[29] = 1;
      break;
    case 536870911:
      check[28] = 1;
      break;
    case 268435455:
      check[27] = 1;
      break;
    case 134217727:
      check[26] = 1;
      break;
    case 67108863:
      check[25] = 1;
      break;
    case 33554431:
      check[24] = 1;
      break;
    case 16777215:
      check[23] = 1;
      break;
    case 8388607:
      check[22] = 1;
      break;
    case 4194303:
      check[21] = 1;
      break;
    case 2097151:
      check[20] = 1;
      break;
    case 1048575:
      check[19] = 1;
      break;
    case 524287:
      check[18] = 1;
      break;
    case 262143:
      check[17] = 1;
      break;
    case 131071:
      check[16] = 1;
      break;
    case 65535:
      check[15] = 1;
      break;
    case 32767:
      check[14] = 1;
      break;
    case 16383:
      check[13] = 1;
      break;
    case 8191:
      check[12] = 1;
      break;
    case 4095:
      check[11] = 1;
      break;
    case 2047:
      check[10] = 1;
      break;
    case 1023:
      check[9] = 1;
      break;
    case 511:
      check[8] = 1;
      break;
    case 255:
      check[7] = 1;
      break;
    case 127:
      check[6] = 1;
      break;
    case 63:
      check[5] = 1;
      break;
    case 31:
      check[4] = 1;
      break;
    case 15:
      check[3] = 1;
      break;
    case 7:
      check[2] = 1;
      break;
    case 3:
      check[1] = 1;
      break;
    case 1:
      check[0] = 1;
      break;
    }
  }

  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (check[bit] > 0) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Submission Info

Submission Time
Task C - Cheating Nim
User kenkoooo
Language C (GCC 5.4.1)
Score 0
Code Size 2325 Byte
Status WA
Exec Time 5 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:11:3: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration]
   scanf("%d", &n);
   ^
./Main.c:11:3: warning: incompatible implicit declaration of built-in function ‘scanf’
./Main.c:11:3: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
./Main.c:15:11: warning: implicit declaration of function ‘getchar_unlocked’ [-Wimplicit-function-declaration]
       c = getchar_unlocked();
           ^
./Main.c:132:5: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
     printf("-1\n");
     ^
./Main.c:132:5: warning: incompatible implicit declaration of built-in function ‘printf’
./Main.c:132:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
./Main.c:134:5: warning: incompatible implicit declaration of built-in function ‘printf’
     printf("%d\n", ans);
     ^
./Main.c:134:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 1
AC × 9
WA × 17
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 WA 0 ms 128 KB
001.txt WA 0 ms 128 KB
002.txt WA 4 ms 128 KB
003.txt WA 2 ms 128 KB
004.txt AC 2 ms 128 KB
005.txt AC 2 ms 128 KB
006.txt WA 5 ms 128 KB
007.txt WA 5 ms 128 KB
008.txt WA 5 ms 128 KB
009.txt WA 5 ms 128 KB
010.txt WA 5 ms 128 KB
011.txt WA 5 ms 128 KB
012.txt WA 5 ms 128 KB
013.txt WA 5 ms 128 KB
014.txt WA 5 ms 128 KB
015.txt WA 5 ms 128 KB
016.txt AC 5 ms 128 KB
017.txt AC 5 ms 128 KB
018.txt WA 5 ms 128 KB
019.txt WA 5 ms 128 KB
020.txt AC 5 ms 128 KB
021.txt AC 1 ms 128 KB
022.txt AC 1 ms 128 KB
023.txt AC 5 ms 128 KB
example0.txt WA 1 ms 128 KB
example1.txt AC 0 ms 128 KB