AtCoder Regular Contest 069

Submission #1351649

Source codeソースコード

#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N], ret[N];

int n;
bool valid(int x) {
  if (ret[x] == 'W') {
    if (s[x] == 'o') {
      return ret[(x + n - 1) % n] != ret[(x + 1) % n];
    } else {
      return ret[(x + n - 1) % n] == ret[(x + 1) % n];
    }
  } else {
    if (s[x] == 'x') {
      return ret[(x + n - 1) % n] != ret[(x + 1) % n];
    } else {
      return ret[(x + n - 1) % n] == ret[(x + 1) % n];
    }
  }
}

int main() {
  bool found = false;
  scanf("%d%s", &n, s);
  for (int k = 0; k < 4; ++k) {
    ret[0] = (k & 1) ? 'W' : 'S';
    ret[1] = (k & 2) ? 'W' : 'S';
    for (int i = 2; i < n; ++i) {
      if (ret[i - 1] == 'W') {
        if (s[i - 1] == 'o') {
          ret[i] = 'W' + 'S' - ret[i - 2];
        } else {
          ret[i] = ret[i - 2];
        }
      } else {
        if (s[i - 1] == 'o') {
          ret[i] = ret[i - 2];
        } else {
          ret[i] = 'W' + 'S' - ret[i - 2];
        }
      }
    }
    if (valid(n - 1) && valid(0)) {
      found = true;
      break;
    }
  }
  if (!found) {
    puts("-1");
  } else {
    puts(ret);
  }
  return 0;
}

Submission

Task問題 D - Menagerie
User nameユーザ名 cuiaoxiang
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 500
Source lengthソースコード長 2083 Byte
File nameファイル名
Exec time実行時間 4 ms
Memory usageメモリ使用量 512 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:63:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%s", &n, s);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt,00_example_03.txt
All 500 / 500 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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 AC 2 ms 384 KB
02.txt AC 2 ms 384 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 2 ms 512 KB
06.txt AC 2 ms 512 KB
07.txt AC 1 ms 256 KB
08.txt AC 2 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 2 ms 256 KB
11.txt AC 4 ms 512 KB
12.txt AC 4 ms 512 KB
13.txt AC 3 ms 512 KB