結果

問題 No.443 GCD of Permutation
ユーザー bal4ubal4u
提出日時 2019-05-09 13:26:44
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,169 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 29,548 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 17:42:13
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 0 ms
4,380 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 0 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 0 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 0 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 0 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘ins’ 内:
main.c:7:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:22:28: 備考: in expansion of macro ‘gc’
   22 |                 *p++ = c = gc();
      |                            ^~
main.c: 関数 ‘out’ 内:
main.c:8:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:34:17: 備考: in expansion of macro ‘pc’
   34 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// 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;
}
0