답안 #398750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398750 2021-05-04T19:22:06 Z 4fecta Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
668 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 5005;

int n, a[MN], h[MN], c[MN], dp[MN][MN], suf[MN][MN];
vector<int> hs, adj[MN];
map<int, int> mp;

void dfs(int cur) {
    for (int i = 1; i <= hs.size(); i++) dp[cur][i] = i == h[cur] ? 0 : c[cur];
    for (int nxt : adj[cur]) {
        dfs(nxt);
        for (int i = 1; i <= hs.size(); i++) dp[cur][i] += suf[nxt][i];
    }
    for (int i = hs.size(); i > 0; i--) suf[cur][i] = min(dp[cur][i], suf[cur][i + 1]);
}

int32_t main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> h[i] >> c[i];
        if (i > 1) adj[a[i]].push_back(i);
        hs.push_back(h[i]);
    }
    sort(hs.begin(), hs.end());
    hs.erase(unique(hs.begin(), hs.end()), hs.end());
    for (int i = 0; i < hs.size(); i++) mp[hs[i]] = i + 1;
    for (int i = 1; i <= n; i++) h[i] = mp[h[i]];
    memset(dp, 0x3f, sizeof(dp));
    memset(suf, 0x3f, sizeof(suf));
    dfs(1);
    int ans = 1e18;
    for (int i = 1; i <= hs.size(); i++) ans = min(ans, dp[1][i]);
    printf("%lld\n", ans);

    return 0;
}

Compilation message

worst_reporter2.cpp: In function 'void dfs(long long int)':
worst_reporter2.cpp:18:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 1; i <= hs.size(); i++) dp[cur][i] = i == h[cur] ? 0 : c[cur];
      |                     ~~^~~~~~~~~~~~
worst_reporter2.cpp:21:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for (int i = 1; i <= hs.size(); i++) dp[cur][i] += suf[nxt][i];
      |                         ~~^~~~~~~~~~~~
worst_reporter2.cpp: In function 'int32_t main()':
worst_reporter2.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 0; i < hs.size(); i++) mp[hs[i]] = i + 1;
      |                     ~~^~~~~~~~~~~
worst_reporter2.cpp:43:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 1; i <= hs.size(); i++) ans = min(ans, dp[1][i]);
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 392504 KB Output is correct
2 Correct 175 ms 392564 KB Output is correct
3 Correct 185 ms 392536 KB Output is correct
4 Correct 174 ms 392536 KB Output is correct
5 Correct 316 ms 393176 KB Output is correct
6 Correct 181 ms 392900 KB Output is correct
7 Correct 180 ms 392904 KB Output is correct
8 Correct 318 ms 393284 KB Output is correct
9 Correct 181 ms 392900 KB Output is correct
10 Correct 177 ms 392876 KB Output is correct
11 Correct 175 ms 392892 KB Output is correct
12 Correct 346 ms 393740 KB Output is correct
13 Correct 178 ms 393260 KB Output is correct
14 Correct 330 ms 393408 KB Output is correct
15 Correct 184 ms 393184 KB Output is correct
16 Correct 319 ms 393376 KB Output is correct
17 Correct 181 ms 392900 KB Output is correct
18 Correct 179 ms 392868 KB Output is correct
19 Correct 325 ms 393492 KB Output is correct
20 Correct 183 ms 393028 KB Output is correct
21 Correct 185 ms 393028 KB Output is correct
22 Correct 316 ms 393288 KB Output is correct
23 Correct 180 ms 393036 KB Output is correct
24 Correct 328 ms 393556 KB Output is correct
25 Correct 180 ms 393156 KB Output is correct
26 Correct 328 ms 393572 KB Output is correct
27 Correct 321 ms 393348 KB Output is correct
28 Correct 320 ms 393504 KB Output is correct
29 Correct 326 ms 393540 KB Output is correct
30 Correct 337 ms 393428 KB Output is correct
31 Correct 331 ms 393500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 317 ms 393272 KB Output is correct
2 Runtime error 668 ms 524288 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 392504 KB Output is correct
2 Correct 175 ms 392564 KB Output is correct
3 Correct 185 ms 392536 KB Output is correct
4 Correct 174 ms 392536 KB Output is correct
5 Correct 316 ms 393176 KB Output is correct
6 Correct 181 ms 392900 KB Output is correct
7 Correct 180 ms 392904 KB Output is correct
8 Correct 318 ms 393284 KB Output is correct
9 Correct 181 ms 392900 KB Output is correct
10 Correct 177 ms 392876 KB Output is correct
11 Correct 175 ms 392892 KB Output is correct
12 Correct 346 ms 393740 KB Output is correct
13 Correct 178 ms 393260 KB Output is correct
14 Correct 330 ms 393408 KB Output is correct
15 Correct 184 ms 393184 KB Output is correct
16 Correct 319 ms 393376 KB Output is correct
17 Correct 181 ms 392900 KB Output is correct
18 Correct 179 ms 392868 KB Output is correct
19 Correct 325 ms 393492 KB Output is correct
20 Correct 183 ms 393028 KB Output is correct
21 Correct 185 ms 393028 KB Output is correct
22 Correct 316 ms 393288 KB Output is correct
23 Correct 180 ms 393036 KB Output is correct
24 Correct 328 ms 393556 KB Output is correct
25 Correct 180 ms 393156 KB Output is correct
26 Correct 328 ms 393572 KB Output is correct
27 Correct 321 ms 393348 KB Output is correct
28 Correct 320 ms 393504 KB Output is correct
29 Correct 326 ms 393540 KB Output is correct
30 Correct 337 ms 393428 KB Output is correct
31 Correct 331 ms 393500 KB Output is correct
32 Correct 317 ms 393272 KB Output is correct
33 Runtime error 668 ms 524288 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -