結果

問題 No.233 めぐるはめぐる (3)
ユーザー bal4ubal4u
提出日時 2019-08-25 17:23:34
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 61 ms / 1,000 ms
コード長 1,985 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 31,232 KB
実行使用メモリ 16,128 KB
最終ジャッジ日時 2024-04-24 12:18:16
合計ジャッジ時間 3,265 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
16,000 KB
testcase_01 AC 27 ms
16,128 KB
testcase_02 AC 22 ms
16,000 KB
testcase_03 AC 28 ms
16,128 KB
testcase_04 AC 61 ms
16,128 KB
testcase_05 AC 52 ms
16,128 KB
testcase_06 AC 52 ms
16,128 KB
testcase_07 AC 0 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 27 ms
16,000 KB
testcase_13 AC 32 ms
16,000 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:12:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
   12 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:20:24: note: in expansion of macro 'gc'
   20 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'outs':
main.c:13:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   13 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:35:33: note: in expansion of macro 'pc'
   35 | 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>
#include <string.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";
char d2c[] = "_uiearnmgb";

ll ins() {   // 文字列の特殊入力。文字列を11桁10進数に変換
	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) {  // 11桁10進数を文字列に逆変換して表示
	int i;
	for (i = 10; i >= 0; i--) s[i] = d2c[x % 10], x /= 10;
	outs(s);
}

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

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

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

//// 本問題関連

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;
	if (id == 11) {
		if (lookup(x)) { pr(x); exit(0); }
		return;
	}
	x *= 10;
	for (i = 6; i < 11; i++) if (f[i]) {
		f[i] = 0, y = 10*(x + code[i]);
		for (j = 0; j < 6; j++) if (f[j]) {
			f[j] = 0, rec(id+2, y + code[j], bo), f[j] = 1;
		}
		f[i] = 1;
	}
	if (!bo) for (i = 0; i < 6; i++) if (f[i])
		f[i] = 0, rec(id+1, x + code[i], 1), f[i] = 1;
}
		
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());
	
	memset(f, 1, sizeof(f));
	rec(0, 0, 0);
	outs("NO");
	return 0;
}
0