답안 #1050189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050189 2024-08-09T07:54:29 Z 김은성(#11046) 별자리 3 (JOI20_constellation3) C++17
35 / 100
64 ms 39664 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[2009][2009];
vector<pair<int, int> > x[200009];
int a[200009], lc[200009], rc[200009], par[200009];
int n;
int cost(int v, int s, int e){
	auto it1 = lower_bound(x[v].begin(), x[v].end(), make_pair(s, 0)), it2 = upper_bound(x[v].begin(), x[v].end(), make_pair(e, (int)1e9));
	int ans = 0;
	for(auto it = it1; it != x[v].end(); it++){
		ans = max(ans, it->second);
	}
	return ans;
}
void treedp(int v){
	if(v==0)
		return;
	//printf("v=%d lc=%d rc=%d\n", v, lc[v], rc[v]);
	treedp(lc[v]);
	treedp(rc[v]);
	for(int h = 0; h <= n; h++){
		dp[v][h] = max(max(dp[lc[v]][a[v]]+dp[rc[v]][a[v]]+cost(v, h+1, a[v]), dp[lc[v]][a[v]] + dp[rc[v]][h]), 
						dp[lc[v]][h] + dp[rc[v]][a[v]]);
		//printf("dp[%d][%d]=%lld cost=%d\n", v, h, dp[v][h], cost(v, h+1, a[v]));
	}
}
int main(){
	int m, i, j, x1, y1, c1;
	long long ans = 0;
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", &a[i]);
		a[i] = n-a[i];
	}
	scanf("%d", &m);
	for(i=1; i<=m; i++){
		scanf("%d %d %d", &x1, &y1, &c1);
		y1 = n+1-y1;
		x[x1].push_back(make_pair(y1, c1));
		ans += c1;
	}
	for(i=1; i<=n; i++)
		sort(x[i].begin(), x[i].end());
	vector<int> st;
	for(i=1; i<=n; i++){
		while(!st.empty() && a[st.back()] > a[i]){
			rc[i] = st.back();
			st.pop_back();
		}
		if(!st.empty())
			lc[st.back()] = i;
		st.push_back(i);
	}
	int root;
	vector<bool> ch(n+1);
	for(i=1; i<=n; i++){
		ch[lc[i]] = ch[rc[i]] = 1;
	}
	for(i=1; i<=n; i++){
		if(!ch[i]){
			root = i;
			break;
		}
	}
	treedp(root);
	printf("%lld\n", ans - dp[root][0]);
	return 0;
}

Compilation message

constellation3.cpp: In function 'int cost(int, int, int)':
constellation3.cpp:9:69: warning: variable 'it2' set but not used [-Wunused-but-set-variable]
    9 |  auto it1 = lower_bound(x[v].begin(), x[v].end(), make_pair(s, 0)), it2 = upper_bound(x[v].begin(), x[v].end(), make_pair(e, (int)1e9));
      |                                                                     ^~~
constellation3.cpp: In function 'int main()':
constellation3.cpp:29:12: warning: unused variable 'j' [-Wunused-variable]
   29 |  int m, i, j, x1, y1, c1;
      |            ^
constellation3.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
constellation3.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
constellation3.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d", &m);
      |  ~~~~~^~~~~~~~~~
constellation3.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d %d %d", &x1, &y1, &c1);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
constellation3.cpp:67:35: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |  printf("%lld\n", ans - dp[root][0]);
      |                         ~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 12736 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 1 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 12736 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 1 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 15 ms 39256 KB Output is correct
24 Correct 15 ms 39260 KB Output is correct
25 Correct 15 ms 39416 KB Output is correct
26 Correct 16 ms 39260 KB Output is correct
27 Correct 16 ms 39456 KB Output is correct
28 Correct 16 ms 39444 KB Output is correct
29 Correct 16 ms 39260 KB Output is correct
30 Correct 17 ms 39516 KB Output is correct
31 Correct 15 ms 39468 KB Output is correct
32 Correct 27 ms 39596 KB Output is correct
33 Correct 16 ms 39512 KB Output is correct
34 Correct 19 ms 39516 KB Output is correct
35 Correct 22 ms 39464 KB Output is correct
36 Correct 17 ms 39512 KB Output is correct
37 Correct 19 ms 39512 KB Output is correct
38 Correct 21 ms 39664 KB Output is correct
39 Correct 24 ms 39432 KB Output is correct
40 Correct 18 ms 39636 KB Output is correct
41 Correct 24 ms 39204 KB Output is correct
42 Correct 15 ms 39436 KB Output is correct
43 Correct 15 ms 39636 KB Output is correct
44 Correct 17 ms 39260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 1 ms 12636 KB Output is correct
4 Correct 1 ms 12636 KB Output is correct
5 Correct 1 ms 12636 KB Output is correct
6 Correct 2 ms 12636 KB Output is correct
7 Correct 1 ms 12636 KB Output is correct
8 Correct 2 ms 12636 KB Output is correct
9 Correct 2 ms 12636 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 12736 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 2 ms 12636 KB Output is correct
16 Correct 2 ms 14680 KB Output is correct
17 Correct 1 ms 12636 KB Output is correct
18 Correct 2 ms 12636 KB Output is correct
19 Correct 2 ms 12636 KB Output is correct
20 Correct 2 ms 12636 KB Output is correct
21 Correct 2 ms 12636 KB Output is correct
22 Correct 2 ms 12636 KB Output is correct
23 Correct 15 ms 39256 KB Output is correct
24 Correct 15 ms 39260 KB Output is correct
25 Correct 15 ms 39416 KB Output is correct
26 Correct 16 ms 39260 KB Output is correct
27 Correct 16 ms 39456 KB Output is correct
28 Correct 16 ms 39444 KB Output is correct
29 Correct 16 ms 39260 KB Output is correct
30 Correct 17 ms 39516 KB Output is correct
31 Correct 15 ms 39468 KB Output is correct
32 Correct 27 ms 39596 KB Output is correct
33 Correct 16 ms 39512 KB Output is correct
34 Correct 19 ms 39516 KB Output is correct
35 Correct 22 ms 39464 KB Output is correct
36 Correct 17 ms 39512 KB Output is correct
37 Correct 19 ms 39512 KB Output is correct
38 Correct 21 ms 39664 KB Output is correct
39 Correct 24 ms 39432 KB Output is correct
40 Correct 18 ms 39636 KB Output is correct
41 Correct 24 ms 39204 KB Output is correct
42 Correct 15 ms 39436 KB Output is correct
43 Correct 15 ms 39636 KB Output is correct
44 Correct 17 ms 39260 KB Output is correct
45 Runtime error 64 ms 25684 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -