답안 #417184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417184 2021-06-03T12:44:03 Z maomao90 Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
1890 ms 197844 KB
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 5005

int n;
int h[MAXN], c[MAXN];
vi adj[MAXN];
ll memo[MAXN][MAXN];

ll dp(int u, int ptake, int p) {
	if (memo[u][ptake] != -1) return memo[u][ptake];
	int pv = -1;
	if (ptake != -1) {
		pv = h[ptake];
	}
	vector<ll> notake, take;
	for (int v : adj[u]) {
		notake.pb(dp(v, u, u));
		take.pb(dp(v, ptake, u));
	}
	ll notakev = 0, takev = c[u];
	REP (i, 0, notake.size()) {
		notakev += notake[i];
		takev += take[i];
	}
	//printf("%d: %lld %lld\n", u, notakev, takev);
	if (pv > h[u]) {
		return memo[u][ptake] = takev;
	}
	return memo[u][ptake] = min(takev, notakev);
}

int main() {
	scanf("%d", &n);
	REP (i, 1, n + 1) {
		int a; scanf("%d%d%d", &a, &h[i], &c[i]);
		if (i != 1) adj[a].pb(i);
	}
	memset(memo, -1, sizeof memo);
	printf("%lld\n", dp(1, -1, -1));
	return 0;
}

Compilation message

worst_reporter2.cpp: In function 'll dp(int, int, int)':
worst_reporter2.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   47 |  REP (i, 0, notake.size()) {
      |       ~~~~~~~~~~~~~~~~~~~               
worst_reporter2.cpp:47:2: note: in expansion of macro 'REP'
   47 |  REP (i, 0, notake.size()) {
      |  ^~~
worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
worst_reporter2.cpp:61:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   int a; scanf("%d%d%d", &a, &h[i], &c[i]);
      |          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 196416 KB Output is correct
2 Correct 84 ms 196384 KB Output is correct
3 Correct 82 ms 196484 KB Output is correct
4 Correct 80 ms 196384 KB Output is correct
5 Correct 92 ms 196612 KB Output is correct
6 Correct 95 ms 196604 KB Output is correct
7 Correct 93 ms 196616 KB Output is correct
8 Correct 91 ms 196756 KB Output is correct
9 Correct 92 ms 196676 KB Output is correct
10 Correct 93 ms 196724 KB Output is correct
11 Correct 93 ms 196676 KB Output is correct
12 Correct 1873 ms 197824 KB Output is correct
13 Correct 1890 ms 197844 KB Output is correct
14 Correct 916 ms 197444 KB Output is correct
15 Correct 910 ms 197392 KB Output is correct
16 Correct 94 ms 196728 KB Output is correct
17 Correct 92 ms 196692 KB Output is correct
18 Correct 97 ms 196664 KB Output is correct
19 Correct 956 ms 197316 KB Output is correct
20 Correct 969 ms 197188 KB Output is correct
21 Correct 965 ms 197188 KB Output is correct
22 Correct 83 ms 196804 KB Output is correct
23 Correct 84 ms 196924 KB Output is correct
24 Correct 924 ms 197428 KB Output is correct
25 Correct 921 ms 197316 KB Output is correct
26 Correct 1883 ms 197832 KB Output is correct
27 Correct 590 ms 197084 KB Output is correct
28 Correct 1097 ms 197316 KB Output is correct
29 Correct 1589 ms 197640 KB Output is correct
30 Correct 920 ms 197412 KB Output is correct
31 Correct 893 ms 197280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 196416 KB Output is correct
2 Correct 84 ms 196384 KB Output is correct
3 Correct 82 ms 196484 KB Output is correct
4 Correct 80 ms 196384 KB Output is correct
5 Correct 92 ms 196612 KB Output is correct
6 Correct 95 ms 196604 KB Output is correct
7 Correct 93 ms 196616 KB Output is correct
8 Correct 91 ms 196756 KB Output is correct
9 Correct 92 ms 196676 KB Output is correct
10 Correct 93 ms 196724 KB Output is correct
11 Correct 93 ms 196676 KB Output is correct
12 Correct 1873 ms 197824 KB Output is correct
13 Correct 1890 ms 197844 KB Output is correct
14 Correct 916 ms 197444 KB Output is correct
15 Correct 910 ms 197392 KB Output is correct
16 Correct 94 ms 196728 KB Output is correct
17 Correct 92 ms 196692 KB Output is correct
18 Correct 97 ms 196664 KB Output is correct
19 Correct 956 ms 197316 KB Output is correct
20 Correct 969 ms 197188 KB Output is correct
21 Correct 965 ms 197188 KB Output is correct
22 Correct 83 ms 196804 KB Output is correct
23 Correct 84 ms 196924 KB Output is correct
24 Correct 924 ms 197428 KB Output is correct
25 Correct 921 ms 197316 KB Output is correct
26 Correct 1883 ms 197832 KB Output is correct
27 Correct 590 ms 197084 KB Output is correct
28 Correct 1097 ms 197316 KB Output is correct
29 Correct 1589 ms 197640 KB Output is correct
30 Correct 920 ms 197412 KB Output is correct
31 Correct 893 ms 197280 KB Output is correct
32 Correct 94 ms 196628 KB Output is correct
33 Runtime error 12 ms 1172 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 196416 KB Output is correct
2 Correct 84 ms 196384 KB Output is correct
3 Correct 82 ms 196484 KB Output is correct
4 Correct 80 ms 196384 KB Output is correct
5 Correct 92 ms 196612 KB Output is correct
6 Correct 95 ms 196604 KB Output is correct
7 Correct 93 ms 196616 KB Output is correct
8 Correct 91 ms 196756 KB Output is correct
9 Correct 92 ms 196676 KB Output is correct
10 Correct 93 ms 196724 KB Output is correct
11 Correct 93 ms 196676 KB Output is correct
12 Correct 1873 ms 197824 KB Output is correct
13 Correct 1890 ms 197844 KB Output is correct
14 Correct 916 ms 197444 KB Output is correct
15 Correct 910 ms 197392 KB Output is correct
16 Correct 94 ms 196728 KB Output is correct
17 Correct 92 ms 196692 KB Output is correct
18 Correct 97 ms 196664 KB Output is correct
19 Correct 956 ms 197316 KB Output is correct
20 Correct 969 ms 197188 KB Output is correct
21 Correct 965 ms 197188 KB Output is correct
22 Correct 83 ms 196804 KB Output is correct
23 Correct 84 ms 196924 KB Output is correct
24 Correct 924 ms 197428 KB Output is correct
25 Correct 921 ms 197316 KB Output is correct
26 Correct 1883 ms 197832 KB Output is correct
27 Correct 590 ms 197084 KB Output is correct
28 Correct 1097 ms 197316 KB Output is correct
29 Correct 1589 ms 197640 KB Output is correct
30 Correct 920 ms 197412 KB Output is correct
31 Correct 893 ms 197280 KB Output is correct
32 Correct 94 ms 196628 KB Output is correct
33 Runtime error 12 ms 1172 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -