結果
問題 | No.3001 ヘビ文字列 |
ユーザー |
👑 |
提出日時 | 2025-01-02 00:58:47 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,010 ms / 1,500 ms |
コード長 | 873 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 26,624 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-02 00:59:30 |
合計ジャッジ時間 | 36,771 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 83 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%s", S); | ^~~~~~~~~~~~~~
ソースコード
#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;}