提出 #27114943


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
// === Debug macro starts here ===
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x)                                                              \
  {                                                                         \
    ++recur_depth;                                                          \
    auto x_ = x;                                                            \
    --recur_depth;                                                          \
    cerr << string(recur_depth, '	') << "\033[91m" << __func__ << ":" \
         << __LINE__ << "\t" << #x << " = " << x_ << "\033[39m" << endl;    \
  }
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(
    Ostream& os, const Cont& v) {
  os << "[";
  for (auto& x : v) {
    os << x << ", ";
  }
  return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
// === Debug macro ends here ===
#define REP(i, n) for (int i = 0; i < (int)(n); ++(i))
#define REP3(i, s, n) for (int i = (s); i < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) std::begin(x), std::end(x)
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vi;
ll dfs(ll n, vector<ll> T, vector<ll> K, vector<vector<ll>> A, vi done) {
  ll ans{};
  REP_R(i, K[n]) {
    if (done[A[n][i] - 1] == 0) ans += dfs(A[n][i] - 1, T, K, A, done);
  }
  done[n] = 1;
  ans += T[n];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<ll> T(N), K(N);
  vector<vector<ll>> A(N);
  REP(i, N) {
    cin >> T[i] >> K[i];
    vector<ll> b(K[i]);
    REP(j, K[i]) cin >> b[j];
    A[i] = b;
  }

  vi done(N, 0);
  ll ans = dfs(N - 1, T, K, A, done);
  cout << ans << '\n';

  return 0;
}

提出情報

提出日時
問題 C - Martial artist
ユーザ rn4ru
言語 C++ (GCC 9.2.1)
得点 0
コード長 2267 Byte
結果 WA
実行時間 2279 ms
メモリ 2626220 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 300
結果
AC × 2
AC × 15
WA × 3
TLE × 7
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 9 ms 3564 KiB
example_01.txt AC 2 ms 3600 KiB
hand_00.txt TLE 2207 ms 41604 KiB
hand_01.txt TLE 2279 ms 2626220 KiB
hand_02.txt TLE 2206 ms 33488 KiB
hand_03.txt AC 45 ms 20056 KiB
hand_04.txt AC 3 ms 3436 KiB
random_00.txt TLE 2269 ms 2342080 KiB
random_01.txt TLE 2269 ms 2358092 KiB
random_02.txt AC 142 ms 53588 KiB
random_03.txt WA 341 ms 128936 KiB
random_04.txt AC 186 ms 66148 KiB
random_05.txt AC 158 ms 57792 KiB
random_06.txt AC 245 ms 101196 KiB
random_07.txt AC 117 ms 46828 KiB
random_08.txt WA 1044 ms 149872 KiB
random_09.txt WA 1249 ms 181184 KiB
random_10.txt AC 94 ms 34432 KiB
random_11.txt AC 488 ms 95328 KiB
random_12.txt AC 113 ms 33884 KiB
random_13.txt AC 328 ms 64660 KiB
random_14.txt AC 688 ms 33684 KiB
random_15.txt AC 288 ms 33660 KiB
random_16.txt TLE 2206 ms 33436 KiB
random_17.txt TLE 2206 ms 33316 KiB