結果
問題 | No.1609 String Division Machine |
ユーザー |
👑 |
提出日時 | 2021-07-16 22:00:07 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 3,106 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 120,404 KB |
実行使用メモリ | 33,784 KB |
最終ジャッジ日時 | 2024-06-22 11:45:11 |
合計ジャッジ時間 | 2,685 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 37 |
ソースコード
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; }real readReal() { return readToken.to!real; }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)); }enum A = 26;int tr(char c) {return c - 'a' + 1;}char rt(int a) {return cast(char)('a' + (a - 1));}void main() {try {for (; ; ) {const S = readToken();const N = cast(int)(S.length);auto dpR = new int[][](N + 1, A + 2);foreach_reverse (i; 0 .. N) {dpR[i][] = dpR[i + 1][];if (S[i] != '?') {const a = tr(S[i]);/*foreach (b; a + 1 .. A + 2) {chmax(dpR[i][a], 1 + dpR[i + 1][b]);}*/chmax(dpR[i][a], 1 + dpR[i + 1][a + 1]);foreach_reverse (b; 0 .. A + 1) {chmax(dpR[i][b], dpR[i][b + 1]);}}}const lis = max(dpR[0].maxElement, 1);debug {writeln("dpR = ", dpR);writeln("lis = ", lis);}auto ans = S.dup;auto dpL = new int[][](N + 1, A + 2);foreach (i; 0 .. N) {if (ans[i] == '?') {foreach (a; 1 .. A + 1) {// TODObool ok = true;/*foreach (b; 0 .. a) foreach (c; a + 1 .. A + 2) {ok = ok && (dpL[i][b] + 1 + dpR[i + 1][c] <= lis);}*/ok = ok && (dpL[i][a - 1] + 1 + dpR[i + 1][a + 1] <= lis);if (ok) {debug {writeln("ok ", i, " ", rt(a));}ans[i] = rt(a);break;}}}assert(ans[i] != '?');{const a = tr(ans[i]);dpL[i + 1][] = dpL[i][];/*foreach (b; 0 .. a) {chmax(dpL[i + 1][a], dpL[i][b] + 1);}*/chmax(dpL[i + 1][a], dpL[i][a - 1]);foreach (b; 1 .. A + 2) {chmax(dpL[i + 1][b], dpL[i + 1][b - 1]);}}}writeln(ans);}} catch (EOFException e) {}}