답안 #934241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934241 2024-02-27T03:26:02 Z tamir1 Magic Tree (CEOI19_magictree) C++14
61 / 100
795 ms 794964 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,p[100005],i,u,w,d,sum,c;
vector<ll> v[100005],de;
pair<ll,ll> fruit[100005];
vector<vector<ll>> a;
map<ll,ll> mp;
map<ll,ll> ::iterator it;
multiset<ll> s;
multiset<ll> ::iterator is;
bool ar;
void dfs(ll x){
	ll d=fruit[x].first;
	ll w=fruit[x].second;
	d=mp[d];
	a[x][d]=w;
	for(int i:v[x]){
		dfs(i);
		for(int j=1;j<=k;j++){
			a[x][j]+=a[i][j];
		}
	}
	for(int i=2;i<=k;i++) a[x][i]=max(a[x][i-1],a[x][i]);
}
int main(){
	cin >> n >> m >> k;
	ar=true;
	for(i=2;i<=n;i++){
		cin >> p[i];
		if(i-1!=p[i]) ar=false;
		v[p[i]].push_back(i);
	}
	for(i=1;i<=m;i++){
		cin >> u >> d >> w;
		if(w!=1) ar=false;
		mp[d]=1;
		fruit[u]={d,w};
		sum+=w;
		c++;
		de.push_back(d);
	}
	if(ar==true){
		reverse(de.begin(),de.end());
		for(i=0;i<de.size();i++){
			is=s.upper_bound(de[i]);
			if(is!=s.end()) s.erase(is);
			s.insert(de[i]);
		}
		cout << s.size();
		return 0;
	}
	k=0;
	for(it=mp.begin();it!=mp.end();it++){
		k++;
		mp[it->first]=k;
	}
	if(k>1000){
		cout << sum;
		return 0;
	}
	a=vector<vector<ll>> (n+1,vector<ll> (k+1,0));
	dfs(1);
	cout << a[1][k];
}

Compilation message

magictree.cpp: In function 'int main()':
magictree.cpp:45:12: 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]
   45 |   for(i=0;i<de.size();i++){
      |           ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 9268 KB Output is correct
2 Correct 62 ms 9740 KB Output is correct
3 Correct 110 ms 13188 KB Output is correct
4 Correct 97 ms 12228 KB Output is correct
5 Correct 107 ms 12992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 91 ms 14744 KB Output is correct
5 Correct 119 ms 19596 KB Output is correct
6 Correct 137 ms 14792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 15116 KB Output is correct
2 Correct 94 ms 15304 KB Output is correct
3 Correct 110 ms 19012 KB Output is correct
4 Correct 69 ms 13640 KB Output is correct
5 Correct 89 ms 24268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 108 ms 28612 KB Output is correct
11 Correct 100 ms 21124 KB Output is correct
12 Correct 111 ms 32560 KB Output is correct
13 Correct 70 ms 27208 KB Output is correct
14 Correct 77 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 129868 KB Output is correct
2 Correct 640 ms 607792 KB Output is correct
3 Correct 653 ms 611024 KB Output is correct
4 Correct 795 ms 789624 KB Output is correct
5 Correct 661 ms 788416 KB Output is correct
6 Correct 736 ms 792656 KB Output is correct
7 Correct 733 ms 794964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 91 ms 14744 KB Output is correct
14 Correct 119 ms 19596 KB Output is correct
15 Correct 137 ms 14792 KB Output is correct
16 Correct 108 ms 28612 KB Output is correct
17 Correct 100 ms 21124 KB Output is correct
18 Correct 111 ms 32560 KB Output is correct
19 Correct 70 ms 27208 KB Output is correct
20 Correct 77 ms 10584 KB Output is correct
21 Incorrect 16 ms 5720 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4696 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 49 ms 9268 KB Output is correct
11 Correct 62 ms 9740 KB Output is correct
12 Correct 110 ms 13188 KB Output is correct
13 Correct 97 ms 12228 KB Output is correct
14 Correct 107 ms 12992 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 91 ms 14744 KB Output is correct
19 Correct 119 ms 19596 KB Output is correct
20 Correct 137 ms 14792 KB Output is correct
21 Correct 100 ms 15116 KB Output is correct
22 Correct 94 ms 15304 KB Output is correct
23 Correct 110 ms 19012 KB Output is correct
24 Correct 69 ms 13640 KB Output is correct
25 Correct 89 ms 24268 KB Output is correct
26 Correct 108 ms 28612 KB Output is correct
27 Correct 100 ms 21124 KB Output is correct
28 Correct 111 ms 32560 KB Output is correct
29 Correct 70 ms 27208 KB Output is correct
30 Correct 77 ms 10584 KB Output is correct
31 Correct 128 ms 129868 KB Output is correct
32 Correct 640 ms 607792 KB Output is correct
33 Correct 653 ms 611024 KB Output is correct
34 Correct 795 ms 789624 KB Output is correct
35 Correct 661 ms 788416 KB Output is correct
36 Correct 736 ms 792656 KB Output is correct
37 Correct 733 ms 794964 KB Output is correct
38 Incorrect 16 ms 5720 KB Output isn't correct
39 Halted 0 ms 0 KB -