結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
![]() |
提出日時 | 2019-05-09 13:37:12 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 1,130 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 30,720 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 00:08:53 |
合計ジャッジ時間 | 1,079 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
コンパイルメッセージ
main.c: In function 'ins': main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 7 | #define gc() getchar_unlocked() | ^~~~~~~~~~~~~~~~ main.c:22:28: note: in expansion of macro 'gc' 22 | *p++ = c = gc(); | ^~ main.c: In function 'out': main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration] 8 | #define pc(c) putchar_unlocked(c) | ^~~~~~~~~~~~~~~~ main.c:34:17: note: in expansion of macro 'pc' 34 | if (!n) pc('0'); | ^~
ソースコード
// yukicoder: No.443 GCD of Permutation // 2019.5.8 bal4u #include <stdio.h> #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int f[10]; char s[10003]; void ins() { int c; char *p = s; while (1) { *p++ = c = gc(); if (c <= ' ') break; f[c & 0xf]++; } *(p-1) = 0; } void out(int n) { int i; char ob[20]; if (!n) pc('0'); else { i = 0; while (n) ob[i++] = n%10 + '0', n/=10; while (i--) pc(ob[i]); } } void outs(char *s) { while (*s) pc(*s++); } int gcd(int a, int b) { int r; while (b != 0) r = a % b, a = b, b = r; return a; } int bigGCD(char *s, int b) { int a, r; r = 0; while (*s) { a = *s++ & 0xf; if (*s) a = a * 10 + (*s++ & 0xf); r = (r*100 + a) % b; } return gcd(b, r); } int main() { int i, j, g; ins(); j = 0; for (i = 0; i < 10; i++) if (f[i]) j++; if (j == 1) outs(s); else { g = 0; for (i = 0; i < 10; i++) if (f[i]) { for (j = i+1; j < 10; j++) if (f[j]) { if (g == 0) g = 9*(j-i); else g = gcd(g, 9*(j-i)); } } out(bigGCD(s, g)); } pc('\n'); return 0; }