結果

問題 No.398 ハーフパイプ(2)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-30 08:03:47
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 2,148 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 106,484 KB
実行使用メモリ 168,532 KB
最終ジャッジ日時 2023-09-03 23:23:27
合計ジャッジ時間 8,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 383 ms
168,532 KB
testcase_01 AC 385 ms
168,288 KB
testcase_02 AC 382 ms
167,252 KB
testcase_03 AC 378 ms
167,228 KB
testcase_04 AC 383 ms
167,032 KB
testcase_05 AC 386 ms
167,508 KB
testcase_06 AC 389 ms
166,816 KB
testcase_07 AC 387 ms
167,024 KB
testcase_08 AC 388 ms
168,320 KB
testcase_09 AC 391 ms
166,744 KB
testcase_10 AC 382 ms
168,072 KB
testcase_11 AC 386 ms
168,032 KB
testcase_12 AC 378 ms
167,780 KB
testcase_13 AC 380 ms
166,744 KB
testcase_14 AC 379 ms
166,800 KB
testcase_15 AC 376 ms
167,012 KB
testcase_16 AC 377 ms
166,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, 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 N = 6;
enum L = 100;

void main() {
  auto dp = new long[][][][](2, L + 1, L + 1, N * L + 1);
  foreach (k; 0 .. L + 1) {
    dp[0][k][k][k] = 1;
  }
  foreach (i; 1 .. N) {
    auto crt = dp[1 - i % 2], nxt = dp[i % 2];
    foreach (x; 0 .. L + 1) foreach (y; x .. L + 1) {
      nxt[x][y][] = 0;
    }
    foreach (x; 0 .. L + 1) foreach (y; x .. L + 1) foreach (z; 0 .. N * L + 1) {
      if (crt[x][y][z] != 0) {
        foreach (k; 0 .. x) {
          nxt[k][y][z + k] += crt[x][y][z];
        }
        foreach (k; x .. y + 1) {
          nxt[x][y][z + k] += crt[x][y][z];
        }
        foreach (k; y + 1 .. L + 1) {
          nxt[x][k][z + k] += crt[x][y][z];
        }
      }
    }
  }
  
  try {
    for (; ; ) {
      const X = readReal();
      long ans;
      foreach (x; 0 .. L + 1) foreach (y; 0 .. L + 1) foreach (z; 0 .. N * L + 1) {
        if ((z - x - y) / 4.0 == X) {
          ans += dp[(N - 1) % 2][x][y][z];
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0