結果

問題 No.1111 コード進行
ユーザー xuanjixuanji
提出日時 2020-07-10 22:51:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 169,980 KB
実行使用メモリ 220,800 KB
最終ジャッジ日時 2024-04-19 18:01:22
合計ジャッジ時間 4,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,168 KB
testcase_01 AC 3 ms
6,656 KB
testcase_02 AC 3 ms
5,888 KB
testcase_03 AC 2 ms
5,760 KB
testcase_04 AC 3 ms
5,760 KB
testcase_05 AC 3 ms
6,528 KB
testcase_06 AC 4 ms
10,112 KB
testcase_07 AC 5 ms
13,568 KB
testcase_08 AC 5 ms
13,056 KB
testcase_09 AC 4 ms
7,040 KB
testcase_10 AC 6 ms
17,280 KB
testcase_11 AC 4 ms
11,648 KB
testcase_12 AC 4 ms
10,112 KB
testcase_13 AC 4 ms
9,344 KB
testcase_14 AC 8 ms
12,928 KB
testcase_15 AC 6 ms
15,872 KB
testcase_16 AC 5 ms
10,752 KB
testcase_17 AC 6 ms
17,408 KB
testcase_18 AC 4 ms
12,800 KB
testcase_19 AC 2 ms
5,760 KB
testcase_20 AC 4 ms
7,168 KB
testcase_21 AC 5 ms
14,336 KB
testcase_22 AC 5 ms
16,512 KB
testcase_23 AC 4 ms
12,288 KB
testcase_24 AC 4 ms
10,880 KB
testcase_25 AC 8 ms
17,408 KB
testcase_26 AC 11 ms
14,976 KB
testcase_27 AC 3 ms
6,528 KB
testcase_28 AC 36 ms
133,248 KB
testcase_29 AC 34 ms
127,616 KB
testcase_30 AC 52 ms
88,576 KB
testcase_31 AC 8 ms
21,632 KB
testcase_32 AC 86 ms
166,656 KB
testcase_33 AC 75 ms
57,856 KB
testcase_34 AC 31 ms
112,640 KB
testcase_35 AC 52 ms
194,688 KB
testcase_36 AC 38 ms
135,040 KB
testcase_37 AC 35 ms
124,672 KB
testcase_38 AC 59 ms
90,112 KB
testcase_39 AC 135 ms
84,480 KB
testcase_40 AC 134 ms
141,952 KB
testcase_41 AC 43 ms
156,672 KB
testcase_42 AC 36 ms
133,504 KB
testcase_43 AC 106 ms
86,528 KB
testcase_44 AC 22 ms
78,080 KB
testcase_45 AC 34 ms
131,200 KB
testcase_46 AC 58 ms
220,544 KB
testcase_47 AC 60 ms
220,800 KB
testcase_48 AC 61 ms
220,800 KB
testcase_49 AC 58 ms
220,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:43:23: warning: iteration 305 invokes undefined behavior [-Waggressive-loop-optimizations]
   43 |         memo[i][j][k] = -1;
      |         ~~~~~~~~~~~~~~^~~~
main.cpp:42:22: note: within this loop
   42 |       for (int k=0; k<=MAX_K; k++) {
      |                     ~^~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr size_t MAX_N = 305;
constexpr size_t MAX_K = 305;
constexpr size_t NUM_CHORDS = 305;

constexpr int MODULUS = 1000000007;

long long memo[MAX_N][NUM_CHORDS][MAX_K];

vector<set<pair<int,int>>> neighbours(NUM_CHORDS);

int N, M, K;

long long ans(int length, int last, int target) {
  if (length == 1) {
    if (target == 0) return 1;
    return 0;
  }
  if (target < 0) return 0;

  if (memo[length][last][target] != -1) return memo[length][last][target];

  long long ret = 0;
  for (auto const& p : neighbours[last]) {
    auto prev = p.first;
    auto cost = p.second;

    ret += ans(length-1, prev, target-cost);
    ret = ret % MODULUS;
  }

  return memo[length][last][target] = ret;
}

int main() {
  cin >> N >> M >> K;

  for (int i=0; i<=N; i++) {
    for (int j=0; j<=300; j++) {
      for (int k=0; k<=MAX_K; k++) {
        memo[i][j][k] = -1;
      }
    }
  }

  for (int i=0; i<M; i++) {
    int P, Q, C;
    cin >> P >> Q >> C;
    neighbours[Q].insert(make_pair(P, C));
  }

  int ret = 0;
  for (int v=1; v<=300; v++) {
    ret += ans(N, v, K);
    ret = ret % MODULUS;
  }

  cout << ret << endl;

  return 0;
}
0