Submission #1494524


Source Code Expand

#include <cstdint>
#include <iostream>

using namespace std;

#define MAX_ANIMALS 100000
char animals[MAX_ANIMALS];
char answers[MAX_ANIMALS];

void decide_animals(uint64_t N)
{
  for (uint64_t i = 1; i < N - 1; i++) {
    switch (animals[i]) {
    case 'S':
      if (answers[i] == 'o') {
        animals[i + 1] = animals[i - 1];
      } else {
        animals[i + 1] = animals[i - 1] == 'S' ? 'W' : 'S';
      }
      break;
    case 'W':
      if (answers[i] == 'x') {
        animals[i + 1] = animals[i - 1];
      } else {
        animals[i + 1] = animals[i - 1] == 'S' ? 'W' : 'S';
      }
      break;
    }
  }
}

bool check_validity(uint64_t N)
{
  switch (animals[N - 1]) {
  case 'S':
    if (answers[N - 1] == 'o') {
      return animals[N - 2] == animals[0];
    } else {
      return animals[N - 2] != animals[0];
    }
    break;
  case 'W':
    if (answers[N - 1] == 'x') {
      return animals[N - 2] == animals[0];
    } else {
      return animals[N - 2] != animals[0];
    }
    break;
  }
  return false;
}

void valid(uint64_t N)
{
  for (uint64_t i = 0; i < N; i++) {
    cout << animals[i];
  }
  cout << endl;
}

void invalid()
{
  cout << -1 << endl;
}

int32_t main()
{
  uint64_t N;
  cin >> N;

  for (uint64_t i = 0; i < N; i++) {
    char answer;
    cin >> answer;
    answers[i] = answer;
  }

  animals[0] = 'S';
  animals[1] = 'S';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  animals[0] = 'S';
  animals[1] = 'W';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  animals[0] = 'W';
  animals[1] = 'S';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  animals[0] = 'W';
  animals[1] = 'W';
  decide_animals(N);
  if (check_validity(N)) {
    valid(N);
    return 0;
  }

  invalid();

  return 0;
}

Submission Info

Submission Time
Task D - Menagerie
User mohei
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1951 Byte
Status WA
Exec Time 11 ms
Memory 512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 9
WA × 7
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
00_example_03.txt AC 1 ms 256 KB
01.txt WA 7 ms 384 KB
02.txt AC 5 ms 384 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt WA 10 ms 512 KB
06.txt AC 9 ms 512 KB
07.txt WA 2 ms 256 KB
08.txt AC 3 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt WA 3 ms 256 KB
11.txt WA 10 ms 512 KB
12.txt WA 10 ms 512 KB
13.txt WA 11 ms 512 KB