結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー | bal4u |
提出日時 | 2019-08-25 16:53:52 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 63 ms / 1,000 ms |
コード長 | 1,918 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 31,104 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-11-06 19:27:07 |
合計ジャッジ時間 | 2,959 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 |
コンパイルメッセージ
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'); } | ^~
ソースコード
// 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; }