Submission #442009

# Submission time Handle Problem Language Result Execution time Memory
442009 2021-07-06T17:49:08 Z cheetose Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
1089 ms 424800 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

Vi v[200001];
int h[200001];
ll c[200001];
ll d[5001][5001];
ll go(int N,int P){
	if(v[N].empty()){
		if(h[N]>=P)return 0;
		return c[N];
	}
	ll &ret=d[N][P];
	if(~ret)return ret;
	ret=INF;
	ll tmp=0;
	if(h[N]<P){
		for(int next:v[N]){
			tmp+=go(next,P);
		}
		return ret=tmp+c[N];
	}
	for(int next:v[N]){
		tmp+=go(next,P);
	}
	ret=min(ret,tmp+c[N]);
	tmp=0;
	for(int next:v[N]){
		tmp+=go(next,h[N]);
	}
	ret=min(ret,tmp);
	return ret;
}
int main(){
	MEM_1(d);
	int n;
	scanf("%d",&n);
	Vi vv={0};
	fup(i,1,n,1){
		int x;
		scanf("%d%d%lld",&x,&h[i],&c[i]);
		if(i!=x)v[x].pb(i);
		vv.pb(h[i]);
	}
	COMPRESS(vv);
	fup(i,1,n,1)h[i]=lower_bound(ALL(vv),h[i])-vv.begin();
	printf("%lld\n",go(1,1));
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
worst_reporter2.cpp:78:2: note: in expansion of macro 'fup'
   78 |  fup(i,1,n,1){
      |  ^~~
worst_reporter2.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
worst_reporter2.cpp:85:2: note: in expansion of macro 'fup'
   85 |  fup(i,1,n,1)h[i]=lower_bound(ALL(vv),h[i])-vv.begin();
      |  ^~~
worst_reporter2.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
worst_reporter2.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%d%d%lld",&x,&h[i],&c[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 97 ms 200772 KB Output is correct
2 Correct 94 ms 200748 KB Output is correct
3 Correct 95 ms 200740 KB Output is correct
4 Correct 94 ms 200716 KB Output is correct
5 Correct 99 ms 201012 KB Output is correct
6 Correct 99 ms 201024 KB Output is correct
7 Correct 98 ms 201028 KB Output is correct
8 Correct 98 ms 201004 KB Output is correct
9 Correct 99 ms 200944 KB Output is correct
10 Correct 98 ms 201028 KB Output is correct
11 Correct 95 ms 201000 KB Output is correct
12 Correct 1089 ms 201496 KB Output is correct
13 Correct 102 ms 201392 KB Output is correct
14 Correct 540 ms 201416 KB Output is correct
15 Correct 108 ms 201288 KB Output is correct
16 Correct 99 ms 201032 KB Output is correct
17 Correct 97 ms 201040 KB Output is correct
18 Correct 95 ms 201028 KB Output is correct
19 Correct 377 ms 201140 KB Output is correct
20 Correct 103 ms 201276 KB Output is correct
21 Correct 95 ms 201216 KB Output is correct
22 Correct 95 ms 200960 KB Output is correct
23 Correct 97 ms 201028 KB Output is correct
24 Correct 404 ms 201256 KB Output is correct
25 Correct 105 ms 201160 KB Output is correct
26 Correct 495 ms 201504 KB Output is correct
27 Correct 263 ms 201092 KB Output is correct
28 Correct 470 ms 201312 KB Output is correct
29 Correct 686 ms 201388 KB Output is correct
30 Correct 491 ms 201284 KB Output is correct
31 Correct 514 ms 201284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 200772 KB Output is correct
2 Correct 94 ms 200748 KB Output is correct
3 Correct 95 ms 200740 KB Output is correct
4 Correct 94 ms 200716 KB Output is correct
5 Correct 99 ms 201012 KB Output is correct
6 Correct 99 ms 201024 KB Output is correct
7 Correct 98 ms 201028 KB Output is correct
8 Correct 98 ms 201004 KB Output is correct
9 Correct 99 ms 200944 KB Output is correct
10 Correct 98 ms 201028 KB Output is correct
11 Correct 95 ms 201000 KB Output is correct
12 Correct 1089 ms 201496 KB Output is correct
13 Correct 102 ms 201392 KB Output is correct
14 Correct 540 ms 201416 KB Output is correct
15 Correct 108 ms 201288 KB Output is correct
16 Correct 99 ms 201032 KB Output is correct
17 Correct 97 ms 201040 KB Output is correct
18 Correct 95 ms 201028 KB Output is correct
19 Correct 377 ms 201140 KB Output is correct
20 Correct 103 ms 201276 KB Output is correct
21 Correct 95 ms 201216 KB Output is correct
22 Correct 95 ms 200960 KB Output is correct
23 Correct 97 ms 201028 KB Output is correct
24 Correct 404 ms 201256 KB Output is correct
25 Correct 105 ms 201160 KB Output is correct
26 Correct 495 ms 201504 KB Output is correct
27 Correct 263 ms 201092 KB Output is correct
28 Correct 470 ms 201312 KB Output is correct
29 Correct 686 ms 201388 KB Output is correct
30 Correct 491 ms 201284 KB Output is correct
31 Correct 514 ms 201284 KB Output is correct
32 Correct 98 ms 200976 KB Output is correct
33 Runtime error 457 ms 424800 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 200772 KB Output is correct
2 Correct 94 ms 200748 KB Output is correct
3 Correct 95 ms 200740 KB Output is correct
4 Correct 94 ms 200716 KB Output is correct
5 Correct 99 ms 201012 KB Output is correct
6 Correct 99 ms 201024 KB Output is correct
7 Correct 98 ms 201028 KB Output is correct
8 Correct 98 ms 201004 KB Output is correct
9 Correct 99 ms 200944 KB Output is correct
10 Correct 98 ms 201028 KB Output is correct
11 Correct 95 ms 201000 KB Output is correct
12 Correct 1089 ms 201496 KB Output is correct
13 Correct 102 ms 201392 KB Output is correct
14 Correct 540 ms 201416 KB Output is correct
15 Correct 108 ms 201288 KB Output is correct
16 Correct 99 ms 201032 KB Output is correct
17 Correct 97 ms 201040 KB Output is correct
18 Correct 95 ms 201028 KB Output is correct
19 Correct 377 ms 201140 KB Output is correct
20 Correct 103 ms 201276 KB Output is correct
21 Correct 95 ms 201216 KB Output is correct
22 Correct 95 ms 200960 KB Output is correct
23 Correct 97 ms 201028 KB Output is correct
24 Correct 404 ms 201256 KB Output is correct
25 Correct 105 ms 201160 KB Output is correct
26 Correct 495 ms 201504 KB Output is correct
27 Correct 263 ms 201092 KB Output is correct
28 Correct 470 ms 201312 KB Output is correct
29 Correct 686 ms 201388 KB Output is correct
30 Correct 491 ms 201284 KB Output is correct
31 Correct 514 ms 201284 KB Output is correct
32 Correct 98 ms 200976 KB Output is correct
33 Runtime error 457 ms 424800 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -