結果

問題 No.380 悪の台本
ユーザー motimoti
提出日時 2016-06-17 23:26:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 3,037 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 114,884 KB
実行使用メモリ 5,528 KB
最終ジャッジ日時 2023-08-06 19:38:46
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,416 KB
testcase_01 AC 3 ms
5,460 KB
testcase_02 AC 2 ms
5,412 KB
testcase_03 AC 2 ms
5,516 KB
testcase_04 AC 6 ms
5,528 KB
testcase_05 AC 15 ms
5,460 KB
testcase_06 AC 15 ms
5,460 KB
testcase_07 AC 131 ms
5,452 KB
testcase_08 AC 4 ms
5,456 KB
testcase_09 AC 8 ms
5,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

bool iskigou(char c) {
  if(isalpha(c)) return false;
  if(isdigit(c)) return false;
  return true;
}

void seriseri(char* serihu) {
  int i =0;
  while(serihu[i] != 0) {
    if(isalpha(serihu[i]))
      if(isupper(serihu[i]))
        serihu[i] += 'a' - 'A';
    i++;
  }
}

void ng() {
  cout << "WRONG!" << endl;
}

int main() {

  char c;
  static char serihu[10000000], name[10000000];
  int k = 0;
  bool hasSpace = 0;
  while ( (c=fgetc(stdin)) != EOF) {
    if(c == '\n') {
//      cout << "\"" << name << "\"" << " " << "\"" << serihu << "\"" << endl;
      serihu[k] = 0;
      seriseri(serihu);

      int f = 0;
      string matu;

      if(0 == strcmp(name, "digi")) f = 0;
      else if(0 == strcmp(name, "petit")) f = 1;
      else if(0 == strcmp(name, "piyo")) f = 2;
      else if(0 == strcmp(name, "gema")) f = 3;
      else if(0 == strcmp(name, "rabi")) f = 4;
      else { ng(); goto ex; }

      if(f < 3 && k < 3) { ng(); goto ex; }
      else if(f == 3 && k < 4) { ng(); goto ex; }

      switch (f) {
        case 0: matu = "nyo"; break;
        case 1: matu = "nyu"; break;
        case 2: matu = "pyo"; break;
        case 3: matu = "gema"; break;
        case 4: ; break;
        default: assert(0);
      }

      if(f < 4) {
        int i = 0;
        if(iskigou(serihu[k - 1])) {
          while(i < 3 && iskigou(serihu[k - 1 - i])) i++;
        }
        reverse(all(matu));
        bool ngflag = 0;
        for(auto c: matu) {
          if(k - 1 - i < 0) {
            ngflag = 1; break;
          }
          if(c != serihu[k - 1 - i]) {
            ngflag = 1; break;
          }
          i ++;
        }
        if(ngflag) { ng(); goto ex; }
      }
      else {
        bool ok = 0;
        rep(i, k) if(!iskigou(serihu[i])) ok = 1;
        if(!ok) { ng(); goto ex; }
      }

      cout << "CORRECT (maybe)" << endl;

    ex:;
      hasSpace = 0;
      k = 0;
      continue;
    }

    if(!hasSpace && c == ' ') {
      name[k] = 0;
      k = 0;
      hasSpace = 1;
      continue;
    }

    if(hasSpace) {
      serihu[k++] = c;
    }
    else {
      name[k++] = c;
    }
  }
  
  return 0;
}
0