結果

問題 No.1609 String Division Machine
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-07-16 22:00:07
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 3,106 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 107,640 KB
実行使用メモリ 34,756 KB
最終ジャッジ日時 2023-09-04 13:13:55
合計ジャッジ時間 4,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 56 ms
34,756 KB
testcase_34 AC 59 ms
32,324 KB
testcase_35 AC 57 ms
33,304 KB
testcase_36 AC 54 ms
33,960 KB
testcase_37 AC 58 ms
33,604 KB
testcase_38 AC 55 ms
34,252 KB
testcase_39 AC 51 ms
33,984 KB
testcase_40 AC 57 ms
34,220 KB
testcase_41 AC 54 ms
33,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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) {
            // TODO
            bool 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) {
  }
}
0