Submission #110546

# Submission time Handle Problem Language Result Execution time Memory
110546 2019-05-11T06:49:39 Z Pro_ktmr Fireworks (APIO16_fireworks) C++14
0 / 100
2000 ms 7424 KB
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

struct f{
	LL a=0, b=0; //xが十分に大きいとき、f(x)=ax+b
	priority_queue<LL> *pq; //傾きが1変わる箇所(ダブりあり)
	void push(LL x){
		pq->push(x);
		pq->push(x);
	}
	void clear(){
		while(!pq->empty()) pq->pop();
	}
	f operator+(f x){
		f ret;
		ret.a = a + x.a;
		ret.b = b + x.b;
		if(pq->size() > x.pq->size()){
			ret.pq = pq;
			while(!x.pq->empty()){
				ret.pq->push(x.pq->top());
				x.pq->pop();
			}
		}
		else{
			ret.pq = x.pq;
			while(!pq->empty()){
				ret.pq->push(pq->top());
				pq->pop();
			}
		}
		return ret;
	}
};

int N, M, par[300001], C[300001];
f node[300001];

int main(){
	scanf("%d%d", &N, &M);
	for(int i=2; i<=N+M; i++) scanf("%d%d", par+i, C+i);
	
	for(int i=1; i<=N+M; i++) node[i].pq = new priority_queue<long long>;
	for(int i=N+M; i>N; i--){
		node[i].a = 1;
		node[i].b = -C[i];
		node[i].push(C[i]);

		node[par[i]] = node[par[i]] + node[i];
		//node[i].clear();
	}
	for(int i=N; i>1; i--){
		while(node[i].a > 1){ //傾きが1より大きい右の方は使わない
			node[i].a--;
			node[i].b += node[i].pq->top();
			node[i].pq->pop();
		}

		//このノードと親との辺の情報を追加
		LL tmp1 = node[i].pq->top();
		node[i].pq->pop();
		LL tmp0 = node[i].pq->top();
		node[i].pq->pop();
		node[i].pq->push(tmp0+C[i]);
		node[i].pq->push(tmp1+C[i]);
		node[i].b -= C[i];

		node[par[i]] = node[par[i]] + node[i];
		node[i].clear();
	}
	while(node[1].a > 0){ //最小のところでは傾きが0
		node[1].a--;
		node[1].b += node[1].pq->top();
		//node[1].pq->pop();
	}
	printf("%lld\n", node[1].b);
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:44:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=2; i<=N+M; i++) scanf("%d%d", par+i, C+i);
                            ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7296 KB Output is correct
2 Incorrect 9 ms 7424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2041 ms 7296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7296 KB Output is correct
2 Incorrect 9 ms 7424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7296 KB Output is correct
2 Incorrect 9 ms 7424 KB Output isn't correct
3 Halted 0 ms 0 KB -