結果

問題 No.3001 ヘビ文字列
ユーザー ygussany
提出日時 2025-01-02 00:58:47
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 1,263 ms / 1,500 ms
コード長 873 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 393 ms
コンパイル使用メモリ 39,808 KB
最終ジャッジ日時 2026-02-22 12:40:04
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 83
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

void chmax(int *a, int b)
{
	if (*a < b) *a = b;
}

int main()
{
	char S[2000001];
	scanf("%s", S);
	
	int i, j, l, n, tmp, max, argmax, min, argmin, num[26];
	for (n = 0; S[n] != 0; n++);
	for (l = 1, min = n; l <= n / 2; l++) {
		if (n % l != 0) continue;
		for (i = 0, tmp = 0; i < l; i++) {
			for (j = 0; j < 26; j++) num[j] = 0;
			for (j = i; j < n; j += l) num[S[j]-'A']++;
			for (j = 0, max = 0; j < 26; j++) chmax(&max, num[j]);
			tmp += max;
		}
		if (min > n - tmp) {
			min = n - tmp;
			argmin = l;
		}
	}
	l = argmin;
	for (i = 0; i < l; i++) {
		for (j = 0; j < 26; j++) num[j] = 0;
		for (j = i; j < n; j += l) num[S[j]-'A']++;
		for (j = 0, max = 0; j < 26; j++) {
			if (max < num[j]) {
				max = num[j];
				argmax = j;
			}
		}
		for (j = i; j < n; j += l) S[j] = 'A' + argmax;
	}
	printf("%s\n", S);
	fflush(stdout);
	return 0;
}
0