Submission #442123

# Submission time Handle Problem Language Result Execution time Memory
442123 2021-07-07T07:42:39 Z cheetose Worst Reporter 4 (JOI21_worst_reporter4) C++17
14 / 100
1025 ms 419928 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 c[N];
		return 0;
	}
	ll &ret=d[N][P];
	if(~ret)return ret;
	ret=0;
	ll tmp=0;
	if(h[N]<P){
		for(int next:v[N]){
			tmp+=go(next,P);
		}
		return ret=tmp;
	}
	for(int next:v[N]){
		tmp+=go(next,P);
	}
	ret=max(ret,tmp);
	tmp=0;
	for(int next:v[N]){
		tmp+=go(next,h[N]);
	}
	ret=max(ret,tmp+c[N]);
	return ret;
}
int main(){
	MEM_1(d);
	int n;
	scanf("%d",&n);
	Vi vv={0};
	ll tot=0;
	fup(i,1,n,1){
		int x;
		scanf("%d%d%lld",&x,&h[i],&c[i]);
		tot+=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",tot-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:79:2: note: in expansion of macro 'fup'
   79 |  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:87:2: note: in expansion of macro 'fup'
   87 |  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:81:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |   scanf("%d%d%lld",&x,&h[i],&c[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 98 ms 200652 KB Output is correct
2 Correct 89 ms 200700 KB Output is correct
3 Correct 88 ms 200672 KB Output is correct
4 Correct 92 ms 200640 KB Output is correct
5 Correct 98 ms 201012 KB Output is correct
6 Correct 97 ms 201056 KB Output is correct
7 Correct 89 ms 201028 KB Output is correct
8 Correct 95 ms 201012 KB Output is correct
9 Correct 93 ms 201028 KB Output is correct
10 Correct 110 ms 201028 KB Output is correct
11 Correct 104 ms 201016 KB Output is correct
12 Correct 1025 ms 201496 KB Output is correct
13 Correct 91 ms 201412 KB Output is correct
14 Correct 501 ms 201296 KB Output is correct
15 Correct 104 ms 201232 KB Output is correct
16 Correct 94 ms 201004 KB Output is correct
17 Correct 91 ms 201024 KB Output is correct
18 Correct 90 ms 201028 KB Output is correct
19 Correct 323 ms 201188 KB Output is correct
20 Correct 103 ms 201164 KB Output is correct
21 Correct 103 ms 201172 KB Output is correct
22 Correct 94 ms 200916 KB Output is correct
23 Correct 90 ms 200920 KB Output is correct
24 Correct 370 ms 201248 KB Output is correct
25 Correct 98 ms 201156 KB Output is correct
26 Correct 404 ms 201412 KB Output is correct
27 Correct 261 ms 201156 KB Output is correct
28 Correct 407 ms 201280 KB Output is correct
29 Correct 601 ms 201432 KB Output is correct
30 Correct 476 ms 201392 KB Output is correct
31 Correct 486 ms 201284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 200652 KB Output is correct
2 Correct 89 ms 200700 KB Output is correct
3 Correct 88 ms 200672 KB Output is correct
4 Correct 92 ms 200640 KB Output is correct
5 Correct 98 ms 201012 KB Output is correct
6 Correct 97 ms 201056 KB Output is correct
7 Correct 89 ms 201028 KB Output is correct
8 Correct 95 ms 201012 KB Output is correct
9 Correct 93 ms 201028 KB Output is correct
10 Correct 110 ms 201028 KB Output is correct
11 Correct 104 ms 201016 KB Output is correct
12 Correct 1025 ms 201496 KB Output is correct
13 Correct 91 ms 201412 KB Output is correct
14 Correct 501 ms 201296 KB Output is correct
15 Correct 104 ms 201232 KB Output is correct
16 Correct 94 ms 201004 KB Output is correct
17 Correct 91 ms 201024 KB Output is correct
18 Correct 90 ms 201028 KB Output is correct
19 Correct 323 ms 201188 KB Output is correct
20 Correct 103 ms 201164 KB Output is correct
21 Correct 103 ms 201172 KB Output is correct
22 Correct 94 ms 200916 KB Output is correct
23 Correct 90 ms 200920 KB Output is correct
24 Correct 370 ms 201248 KB Output is correct
25 Correct 98 ms 201156 KB Output is correct
26 Correct 404 ms 201412 KB Output is correct
27 Correct 261 ms 201156 KB Output is correct
28 Correct 407 ms 201280 KB Output is correct
29 Correct 601 ms 201432 KB Output is correct
30 Correct 476 ms 201392 KB Output is correct
31 Correct 486 ms 201284 KB Output is correct
32 Correct 101 ms 201088 KB Output is correct
33 Runtime error 525 ms 419928 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 200652 KB Output is correct
2 Correct 89 ms 200700 KB Output is correct
3 Correct 88 ms 200672 KB Output is correct
4 Correct 92 ms 200640 KB Output is correct
5 Correct 98 ms 201012 KB Output is correct
6 Correct 97 ms 201056 KB Output is correct
7 Correct 89 ms 201028 KB Output is correct
8 Correct 95 ms 201012 KB Output is correct
9 Correct 93 ms 201028 KB Output is correct
10 Correct 110 ms 201028 KB Output is correct
11 Correct 104 ms 201016 KB Output is correct
12 Correct 1025 ms 201496 KB Output is correct
13 Correct 91 ms 201412 KB Output is correct
14 Correct 501 ms 201296 KB Output is correct
15 Correct 104 ms 201232 KB Output is correct
16 Correct 94 ms 201004 KB Output is correct
17 Correct 91 ms 201024 KB Output is correct
18 Correct 90 ms 201028 KB Output is correct
19 Correct 323 ms 201188 KB Output is correct
20 Correct 103 ms 201164 KB Output is correct
21 Correct 103 ms 201172 KB Output is correct
22 Correct 94 ms 200916 KB Output is correct
23 Correct 90 ms 200920 KB Output is correct
24 Correct 370 ms 201248 KB Output is correct
25 Correct 98 ms 201156 KB Output is correct
26 Correct 404 ms 201412 KB Output is correct
27 Correct 261 ms 201156 KB Output is correct
28 Correct 407 ms 201280 KB Output is correct
29 Correct 601 ms 201432 KB Output is correct
30 Correct 476 ms 201392 KB Output is correct
31 Correct 486 ms 201284 KB Output is correct
32 Correct 101 ms 201088 KB Output is correct
33 Runtime error 525 ms 419928 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -