結果

問題 No.233 めぐるはめぐる (3)
ユーザー bal4ubal4u
提出日時 2019-08-25 16:53:52
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 60 ms / 1,000 ms
コード長 1,918 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 31,872 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-24 11:39:45
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
11,776 KB
testcase_01 AC 22 ms
11,648 KB
testcase_02 AC 17 ms
11,776 KB
testcase_03 AC 24 ms
11,776 KB
testcase_04 AC 60 ms
11,776 KB
testcase_05 AC 36 ms
11,776 KB
testcase_06 AC 32 ms
11,648 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 22 ms
11,648 KB
testcase_13 AC 29 ms
11,776 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:11:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
   11 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:19:24: note: in expansion of macro 'gc'
   19 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'outs':
main.c:12:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   12 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:33:33: note: in expansion of macro 'pc'
   33 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
      |                                 ^~

ソースコード

diff #

// yukicoder: No.233 めぐるはめぐる (3)
// bal4u 2019.8.25

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

//// 高速入力
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

char c2d[128];
char d2c[] = "_aeiubgmnr";

ll ins() {   // 文字列の特殊入力
	ll n = 0; int c = gc();
	do n = 10 * n + c2d[c]; while ((c = gc()) > ' ');
	return n;
}

void outs(char *s) { while (*s) pc(*s++); pc('\n'); }

char s[15];
void pr(ll x) {
	int i;
	for (i = 10; i >= 0; i--) s[i] = d2c[x % 10], x /= 10;
	outs(s);
}

// 数値のハッシュ関数
#define HASHSIZ 1296007
ll hash[HASHSIZ+5], *hashend = hash+HASHSIZ;

int lookup(ll n) {
	ll *p = hash + (int)(n % HASHSIZ);
	while (*p) {
		if (*p == n) return 1;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(ll n) {
	ll *p = hash + (int)(n % HASHSIZ);
	while (*p) {
		if (*p == n) return;
		if (++p == hashend) p = hash;
	}
	*p = n;
}

//// 本問題関連

// char d2c[] = "_aeiubgmnr";
char code[11] = { 1,1,2,3,4,4,5,6,7,8,9 };
char f[11];

void rec(int id, ll x, int bo) {
	int i, j; ll y, z;
	if (id == 11) {
		if (!lookup(x)) { pr(x); exit(0); }
		return;
	}
	for (i = 6; i < 11; i++) {
		if (f[i]) continue;
		f[i] = 1, y = x * 10 + code[i];
		for (j = 0; j < 6; j++) {
			if (f[j]) continue;
			f[j] = 1, z = y * 10 + code[j];
			rec(id+2, z, bo);
			f[j] = 0;
		}
		f[i] = 0;
	}
	if (!bo) {
		for (i = 0; i < 6; i++) {
			if (f[i]) continue;
			f[i] = 1, y = x * 10 + code[i];
			rec(id+1, y, 1);
			f[i] = 0;
		}
	}
}
		
int main()
{
	int i, N;

	for (i = 0; d2c[i]; i++) c2d[d2c[i]] = i;
	N = in();
	if (N == 129600) { outs("NO"); return 0; }
	while (N--) insert(ins());
	
	rec(0, 0, 0);
	outs("NO");
	return 0;
}
0