結果

問題 No.3323 岩井星式ジャンケン
コンテスト
ユーザー tnakao0123
提出日時 2025-11-05 18:56:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,226 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 42,204 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-05 18:56:41
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:66:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3323.cc:  No.3323 蟯ゥ莠墓弌蠑上ず繝」繝ウ繧ア繝ウ - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_M = 100000;
const char hcs[] = "GCP";

/* typedef */

struct Node {
  Node *cs[3];
  Node(): cs() {}
};

/* global variables */

char s[MAX_M + 4], t[MAX_M + 4];
Node *root;

/* subroutines */

inline int c2i(char c) { return (c == 'G') ? 0 : (c == 'C') ? 1 : 2; }

void trie_add(int m, char s[]) {
  Node *u = root;
  for (int i = 0; i < m; i++) {
    int ci = c2i(s[i]);
    if (u->cs[ci] == nullptr) u->cs[ci] = new Node();
    u = u->cs[ci];
  }
}

bool trie_calc(int m, char t[]) {
  Node *u = root;
  for (int i = 0; i < m; i++) {
    if (u == nullptr) t[i] = 'G';
    else {
      int ci = 0;
      while (u->cs[ci] != nullptr) ci++;
      if (ci >= 3) return false;
      ci = (ci + 1) % 3;
      t[i] = hcs[ci];
      u = u->cs[ci];
    }
  }
  t[m] = '\0';
  return true;
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  root = new Node();
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    trie_add(m, s);
  }

  if (trie_calc(m, t))
    puts(t);
  else
    puts("-1");

  return 0;
}

0