結果

問題 No.233 めぐるはめぐる (3)
ユーザー nanasilinanasili
提出日時 2015-07-31 09:36:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 335 ms / 1,000 ms
コード長 1,678 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 89,664 KB
実行使用メモリ 9,540 KB
最終ジャッジ日時 2023-09-24 22:25:42
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
9,352 KB
testcase_01 AC 37 ms
7,184 KB
testcase_02 AC 17 ms
5,300 KB
testcase_03 AC 45 ms
7,620 KB
testcase_04 AC 335 ms
9,472 KB
testcase_05 AC 154 ms
9,500 KB
testcase_06 AC 269 ms
9,540 KB
testcase_07 AC 73 ms
9,540 KB
testcase_08 AC 82 ms
9,500 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 42 ms
7,312 KB
testcase_13 AC 75 ms
9,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

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

  int memo[12] = {50965598, 138640614, 86894790, 22969011, 137866584, 12805388, 102696496, 169269628, 196679944, 213985204, 79308356};

  set <int> hash;
  for (int i = 0; i < n; i++) {
    char s[12];
    scanf("%s", s);
    int t = 0;
    for (int j = 0; j < 12; j++) {
      t += s[j]*memo[j];
    }
    hash.insert(t);
  }
  if (hash.size() >= 129599) {
    puts("NO");
    return 0;
  }

  int ind1[6], ind2[6];
  for (int i = 0; i < 6; i++) {
    ind1[i] = i;
    ind2[i] = i;
  }

  char str[12] = "inabameguru";
  do {
    do {
      char ans[12];
      int temp = 0;
      for (int i = 0; i < 6; i++) {
	temp += str[2*ind1[i]]*memo[2*i];
	ans[2*i] = str[2*ind1[i]];
      }
      for (int i = 0; i < 5; i++) {
	temp += str[2*ind2[i]+1]*memo[2*i+1];
	ans[2*i+1] = str[2*ind2[i]+1];
      }
      ans[11] = '\0';

      if (hash.find(temp) == hash.end()) {
      	puts(ans);
      	return 0;
      }
      for (int i = 0; i < 10; i++) {
	temp += ans[i]*memo[i+1]-ans[i]*memo[i];
	temp += ans[i+1]*memo[i]-ans[i+1]*memo[i+1];
	swap(ans[i], ans[i+1]);
	if (hash.find(temp) == hash.end()) {
	  puts(ans);
	  return 0;
	}
      }

    } while(next_permutation(ind2, ind2+5));
  } while(next_permutation(ind1, ind1+6));
}
0