結果
問題 | No.3001 ヘビ文字列 |
ユーザー | 👑 hos.lyric |
提出日時 | 2025-01-01 08:09:30 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 224 ms / 1,500 ms |
コード長 | 2,457 bytes |
コンパイル時間 | 3,395 ms |
コンパイル使用メモリ | 118,488 KB |
実行使用メモリ | 15,940 KB |
最終ジャッジ日時 | 2025-01-01 08:09:52 |
合計ジャッジ時間 | 21,319 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,820 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 1 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 140 ms
15,248 KB |
testcase_16 | AC | 136 ms
15,068 KB |
testcase_17 | AC | 145 ms
15,264 KB |
testcase_18 | AC | 138 ms
15,752 KB |
testcase_19 | AC | 138 ms
14,600 KB |
testcase_20 | AC | 137 ms
15,940 KB |
testcase_21 | AC | 138 ms
15,660 KB |
testcase_22 | AC | 139 ms
14,756 KB |
testcase_23 | AC | 137 ms
14,796 KB |
testcase_24 | AC | 137 ms
14,852 KB |
testcase_25 | AC | 75 ms
15,268 KB |
testcase_26 | AC | 74 ms
15,252 KB |
testcase_27 | AC | 76 ms
15,604 KB |
testcase_28 | AC | 75 ms
14,940 KB |
testcase_29 | AC | 76 ms
15,200 KB |
testcase_30 | AC | 76 ms
15,048 KB |
testcase_31 | AC | 75 ms
14,456 KB |
testcase_32 | AC | 74 ms
15,068 KB |
testcase_33 | AC | 73 ms
15,036 KB |
testcase_34 | AC | 76 ms
15,052 KB |
testcase_35 | AC | 87 ms
14,260 KB |
testcase_36 | AC | 84 ms
15,360 KB |
testcase_37 | AC | 85 ms
14,952 KB |
testcase_38 | AC | 85 ms
14,936 KB |
testcase_39 | AC | 82 ms
14,996 KB |
testcase_40 | AC | 88 ms
14,308 KB |
testcase_41 | AC | 117 ms
14,724 KB |
testcase_42 | AC | 83 ms
14,352 KB |
testcase_43 | AC | 82 ms
14,628 KB |
testcase_44 | AC | 86 ms
14,908 KB |
testcase_45 | AC | 168 ms
14,272 KB |
testcase_46 | AC | 156 ms
14,524 KB |
testcase_47 | AC | 182 ms
14,248 KB |
testcase_48 | AC | 178 ms
14,220 KB |
testcase_49 | AC | 177 ms
14,860 KB |
testcase_50 | AC | 176 ms
14,676 KB |
testcase_51 | AC | 155 ms
14,832 KB |
testcase_52 | AC | 167 ms
14,952 KB |
testcase_53 | AC | 155 ms
15,308 KB |
testcase_54 | AC | 148 ms
14,424 KB |
testcase_55 | AC | 171 ms
15,328 KB |
testcase_56 | AC | 182 ms
14,872 KB |
testcase_57 | AC | 224 ms
15,016 KB |
testcase_58 | AC | 181 ms
15,168 KB |
testcase_59 | AC | 196 ms
15,256 KB |
testcase_60 | AC | 177 ms
14,884 KB |
testcase_61 | AC | 186 ms
15,188 KB |
testcase_62 | AC | 196 ms
15,276 KB |
testcase_63 | AC | 172 ms
15,568 KB |
testcase_64 | AC | 194 ms
15,296 KB |
testcase_65 | AC | 96 ms
10,576 KB |
testcase_66 | AC | 110 ms
15,580 KB |
testcase_67 | AC | 133 ms
14,876 KB |
testcase_68 | AC | 94 ms
11,492 KB |
testcase_69 | AC | 85 ms
10,980 KB |
testcase_70 | AC | 121 ms
14,984 KB |
testcase_71 | AC | 82 ms
9,628 KB |
testcase_72 | AC | 94 ms
10,668 KB |
testcase_73 | AC | 67 ms
9,072 KB |
testcase_74 | AC | 109 ms
13,336 KB |
testcase_75 | AC | 151 ms
14,364 KB |
testcase_76 | AC | 155 ms
14,420 KB |
testcase_77 | AC | 155 ms
15,264 KB |
testcase_78 | AC | 175 ms
15,628 KB |
testcase_79 | AC | 153 ms
15,584 KB |
testcase_80 | AC | 144 ms
14,484 KB |
testcase_81 | AC | 173 ms
14,772 KB |
testcase_82 | AC | 153 ms
15,252 KB |
testcase_83 | AC | 159 ms
14,280 KB |
testcase_84 | AC | 175 ms
14,180 KB |
testcase_85 | AC | 1 ms
6,816 KB |
testcase_86 | AC | 1 ms
6,816 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const S = readToken; const N = cast(int)(S.length); auto lpf = new int[N + 1]; foreach (p; 2 .. N + 1) lpf[p] = p; foreach (p; 2 .. N + 1) if (lpf[p] == p) { for (int n = p; n <= N; n += p) chmin(lpf[n], p); } int[26] cnt; int opt = N + 1; int dm = -1; foreach (p; 2 .. N + 1) if (lpf[p] == p) if (N % p == 0) { const d = N / p; int cost; foreach (r; 0 .. d) { int mx; for (int i = r; i < N; i += d) chmax(mx, ++cnt[S[i] - 'A']); cost += (N/d - mx); for (int i = r; i < N; i += d) --cnt[S[i] - 'A']; } if (chmin(opt, cost)) { dm = d; } } debug writefln("opt = %s, dm = %s", opt, dm); auto ans = new char[N]; { const d = dm; foreach (r; 0 .. dm) { for (int i = r; i < N; i += d) ++cnt[S[i] - 'A']; int am; foreach (a; 0 .. 26) if (cnt[am] < cnt[a]) am = a; for (int i = r; i < N; i += d) ans[i] = cast(char)('A' + am); for (int i = r; i < N; i += d) --cnt[S[i] - 'A']; } } writeln(ans); } } catch (EOFException e) { } }