結果
| 問題 |
No.443 GCD of Permutation
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-09 13:26:44 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,169 bytes |
| コンパイル時間 | 142 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 00:48:30 |
| 合計ジャッジ時間 | 1,266 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 WA * 5 |
コンパイルメッセージ
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 += a % b;
}
a = b, b = r;
while (b != 0) r = a % b, a = b, b = r;
return a;
}
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;
}
bal4u