結果

問題 No.1935 Water Simulation
ユーザー allegrogikenallegrogiken
提出日時 2022-05-13 23:21:22
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 4,153 bytes
コンパイル時間 782 ms
コンパイル使用メモリ 133,016 KB
実行使用メモリ 44,216 KB
最終ジャッジ日時 2024-06-22 15:12:33
合計ジャッジ時間 5,426 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 110 ms
41,484 KB
testcase_05 AC 109 ms
41,444 KB
testcase_06 AC 112 ms
43,080 KB
testcase_07 AC 113 ms
40,920 KB
testcase_08 AC 110 ms
41,232 KB
testcase_09 AC 111 ms
43,440 KB
testcase_10 AC 116 ms
41,596 KB
testcase_11 AC 110 ms
40,904 KB
testcase_12 AC 113 ms
41,696 KB
testcase_13 AC 114 ms
42,212 KB
testcase_14 AC 112 ms
42,396 KB
testcase_15 AC 110 ms
41,492 KB
testcase_16 AC 120 ms
42,540 KB
testcase_17 AC 119 ms
44,076 KB
testcase_18 AC 114 ms
42,976 KB
testcase_19 AC 116 ms
44,216 KB
testcase_20 AC 115 ms
41,204 KB
testcase_21 AC 120 ms
41,124 KB
testcase_22 AC 114 ms
42,700 KB
testcase_23 AC 117 ms
41,712 KB
testcase_24 AC 118 ms
41,452 KB
testcase_25 AC 115 ms
42,084 KB
testcase_26 AC 118 ms
42,172 KB
testcase_27 AC 118 ms
41,984 KB
testcase_28 AC 119 ms
42,472 KB
testcase_29 AC 115 ms
42,160 KB
testcase_30 AC 113 ms
41,752 KB
testcase_31 AC 119 ms
42,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main() { runSolver(); }

void problem() {
  auto V = scan!int(4);
  auto N = scan!long;

  auto solve() {
    auto vt = new int[][](800001, 4);
    vt[0][0] = V[0];
    int[int[]] history;
    history[vt[0].idup] = 0;
    foreach(i; 1..800001) {
      auto pre = vt[i - 1];
      auto cur = vt[i];
      foreach(j; 0..4) cur[j] = pre[j];

      if (i % 4 == 1) {
        cur[1] = min(cur[0] + pre[1], V[1]);
        cur[0] -= cur[1] - pre[1];
      }
      else if (i % 4 == 2) {
        cur[2] = min(cur[1] + pre[2], V[2]);
        cur[1] -= cur[2] - pre[2];
      }
      else if (i % 4 == 3) {
        cur[3] = min(cur[2] + pre[3], V[3]);
        cur[2] -= cur[3] - pre[3];
      }
      else {
        cur[0] = min(cur[3] + pre[0], V[0]);
        cur[3] -= cur[0] - pre[0];
      }

      if (--N == 0) return cur.toAnswerString;
      if (cur in history) {
        auto cycle = i - history[cur];
        N %= cycle;
        return vt[history[cur] + N].toAnswerString;
      }

      history[cur.idup] = i;
    }

    return "";
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];
0