Submission #709436

# Submission time Handle Problem Language Result Execution time Memory
709436 2023-03-13T14:48:37 Z Antekb Bulldozer (JOI17_bulldozer) C++17
80 / 100
1725 ms 176120 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
	cerr<<h;
	if(sizeof...(t))cerr<<", ";
	debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
const int N=(1<<11), INF=1e9+5;
int wei[N], gdzie[N], gdzie2[N];
ll val[N+N], pref[N+N], suf[N+N], res[N+N];
vector<pii> V2;
ll ans=0;
int n;
void dodaj(int v, int c){
	//deb(v, c);
	val[v+N]+=c;
	pref[v+N]=max(val[v+N], 0ll);
	suf[v+N]=max(val[v+N], 0ll);
	res[v+N]=max(val[v+N], 0ll);
	v+=N;
	v/=2;
	while(v){
		int l=v+v, r=l+1;
		res[v]=max(res[l], res[r]);
		pref[v]=max(pref[l], val[l]+pref[r]);
		suf[v]=max(suf[r], val[r]+suf[l]);
		val[v]=val[l]+val[r];
		res[v]=max(res[v], pref[r]+suf[l]);
		v/=2;
	}
}
ll get_ans(){
	/*ll dp=0, res=0;
	for(int i=n-1; i>=0; i--){
		dp=max(dp+val[i+N], 0ll);
		res=max(res, dp);
	}
	deb(res);*/
	//deb(res[1])
	return res[1];
}
/*void zmien(vector<int> V){
	/*sort(all(V), [](int a, int b){return gdzie[a]<gdzie[b];});
	//assert(V.size()==2);
	int c=gdzie[V[0]];
	ans=max(ans, get_ans());
	for(int i=V.size()-1; i>0;i--){
		dodaj(c, wei[V[i]]);
		dodaj(gdzie[V[i]], -wei[V[i]]);
	}
	ans=max(ans, get_ans());
	for(int i=V.size()-1; i>=0; i--){
		if(i<=V.size()-1-i)break;
		swap(gdzie[V[i]], gdzie[V[V.size()-i-1]]);
	}
	reverse(all(V));
	for(int i=V.size()-1; i>0;i--){
		dodaj(c, -wei[V[i]]);
		dodaj(gdzie[V[i]], wei[V[i]]);
	}
	ans=max(ans, get_ans());
	//for(int i=0; i<n; i++)cout<<gdzie[i]<<" ";cout<<"\n";
	//assert(abs(gdzie[V[0]]-gdzie[V[1]])==1);
	//deb(V[0], V[1], gdzie[V[0]], gdzie[V[1]]);
	ans=max(ans, get_ans());
	dodaj(gdzie[V[0]], wei[V[1]]);
	dodaj(gdzie[V[1]], -wei[V[1]]);
	ans=max(ans, get_ans());
	//deb(val[N], val[N+1], val[N+2], val[N+3]);
	dodaj(gdzie[V[0]], -wei[V[0]]);
	dodaj(gdzie[V[1]], wei[V[0]]);
	swap(gdzie[V[0]], gdzie[V[1]]);
	ans=max(ans, get_ans());
}*/
vector<int> co[N];
int M[N];
void upd(vector<pii> &V){
	//deb(V.size());
	vi uzy;
	for(pii i:V){
		//deb(i.st, i.nd);
		uzy.pb(i.st);
		uzy.pb(i.nd);
		M[i.st]=gdzie[i.st];
		M[i.nd]=gdzie[i.nd];
	}
	//deb();
	sort(uzy.begin(), uzy.end());
	uzy.resize(unique(all(uzy))-uzy.begin());
	for(pii i:V){
		M[i.nd]=min(M[i.nd], gdzie[i.st]);
		M[i.st]=min(M[i.st], gdzie[i.nd]);
	}
	vi waz;
	for(int i:uzy){
		//deb(i);
		co[M[i]].pb(i);
		if(M[i]==gdzie[i])waz.pb(M[i]);
		else {
			//deb(i, gdzie[i], M[i]);
			dodaj(gdzie[i], -wei[i]);
			dodaj(M[i], wei[i]);
		}
	}
	ans=max(ans, get_ans());
	for(int i:waz){
		for(int j:co[i]){
			gdzie[j]=co[i].size()-1+2*i-gdzie[j];
		}
	}
	for(int i:uzy){
		if(M[i]!=gdzie[i]){
			dodaj(gdzie[i], wei[i]);
			dodaj(M[i], -wei[i]);
		}
	}
	ans=max(ans, get_ans());
	for(auto i:waz){
		co[i].clear();
	}
}
int main(){
	cin>>n;
	V2.resize(n);
	for(int i=0; i<n; i++)cin>>V2[i].st>>V2[i].nd>>wei[i], gdzie2[i]=i;
	sort(gdzie2, gdzie2+n, [](int a, int b){if(V2[a].st==V2[b].st)return V2[a].nd>V2[b].nd;return V2[a].st<V2[b].st;});
	for(int i=0; i<n; i++)gdzie[gdzie2[i]]=i;
	for(int i=0; i<n; i++)dodaj(gdzie[i], wei[i]);
	vector<pair<ld, pii> > V;
	for(int i=0; i<n; i++){
		for(int j=0; j<i; j++){
			int x=V2[i].st-V2[j].st, y=V2[i].nd-V2[j].nd;
			if(x>0)y=-y, x=-x;
			if(x==0 && y<0)y=-y;
			ld kat=-atan2(x, y);
			//deb(kat, x, y, i, j);
			V.eb(kat, mp(i, j));
		}
	}
	sort(all(V));
	reverse(all(V));
	vector<pii> todo;
	ans=max(ans, get_ans());
	for(int i=V.size()-1; i>=0; i--){
		todo.pb(V[i].nd);
		if(todo.size()%100==0){
			V.resize(i+1);
		}
		if(i==0 || V[i].st!=V[i-1].st){
			upd(todo);
			todo.clear();
		}
		//zmien({V[i].nd.st, V[i].nd.nd});
	}
	cout<<ans;
}

Compilation message

bulldozer.cpp:58:2: warning: "/*" within comment [-Wcomment]
   58 |  /*sort(all(V), [](int a, int b){return gdzie[a]<gdzie[b];});
      |
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 3 ms 748 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 6 ms 732 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 6 ms 744 KB Output is correct
24 Correct 5 ms 744 KB Output is correct
25 Correct 5 ms 724 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
27 Correct 5 ms 724 KB Output is correct
28 Correct 5 ms 724 KB Output is correct
29 Correct 5 ms 744 KB Output is correct
30 Correct 5 ms 724 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
32 Correct 6 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 6 ms 732 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 6 ms 744 KB Output is correct
24 Correct 5 ms 744 KB Output is correct
25 Correct 5 ms 724 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
27 Correct 5 ms 724 KB Output is correct
28 Correct 5 ms 724 KB Output is correct
29 Correct 5 ms 744 KB Output is correct
30 Correct 5 ms 724 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
32 Correct 6 ms 724 KB Output is correct
33 Correct 1725 ms 66284 KB Output is correct
34 Correct 1588 ms 66284 KB Output is correct
35 Correct 1570 ms 66284 KB Output is correct
36 Correct 1597 ms 66352 KB Output is correct
37 Correct 1588 ms 66284 KB Output is correct
38 Correct 1665 ms 66280 KB Output is correct
39 Correct 1657 ms 66352 KB Output is correct
40 Correct 1642 ms 66304 KB Output is correct
41 Correct 1642 ms 66336 KB Output is correct
42 Correct 1608 ms 66340 KB Output is correct
43 Correct 1547 ms 66356 KB Output is correct
44 Correct 1620 ms 66352 KB Output is correct
45 Correct 1643 ms 66340 KB Output is correct
46 Correct 1505 ms 66276 KB Output is correct
47 Correct 1505 ms 66300 KB Output is correct
48 Correct 1504 ms 66320 KB Output is correct
49 Correct 1508 ms 66284 KB Output is correct
50 Correct 1500 ms 66428 KB Output is correct
51 Correct 1517 ms 66356 KB Output is correct
52 Correct 1480 ms 66256 KB Output is correct
53 Correct 1507 ms 66264 KB Output is correct
54 Correct 1588 ms 66284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 724 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 5 ms 724 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 6 ms 724 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 5 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 6 ms 732 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 5 ms 724 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 6 ms 744 KB Output is correct
24 Correct 5 ms 744 KB Output is correct
25 Correct 5 ms 724 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
27 Correct 5 ms 724 KB Output is correct
28 Correct 5 ms 724 KB Output is correct
29 Correct 5 ms 744 KB Output is correct
30 Correct 5 ms 724 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
32 Correct 6 ms 724 KB Output is correct
33 Correct 1725 ms 66284 KB Output is correct
34 Correct 1588 ms 66284 KB Output is correct
35 Correct 1570 ms 66284 KB Output is correct
36 Correct 1597 ms 66352 KB Output is correct
37 Correct 1588 ms 66284 KB Output is correct
38 Correct 1665 ms 66280 KB Output is correct
39 Correct 1657 ms 66352 KB Output is correct
40 Correct 1642 ms 66304 KB Output is correct
41 Correct 1642 ms 66336 KB Output is correct
42 Correct 1608 ms 66340 KB Output is correct
43 Correct 1547 ms 66356 KB Output is correct
44 Correct 1620 ms 66352 KB Output is correct
45 Correct 1643 ms 66340 KB Output is correct
46 Correct 1505 ms 66276 KB Output is correct
47 Correct 1505 ms 66300 KB Output is correct
48 Correct 1504 ms 66320 KB Output is correct
49 Correct 1508 ms 66284 KB Output is correct
50 Correct 1500 ms 66428 KB Output is correct
51 Correct 1517 ms 66356 KB Output is correct
52 Correct 1480 ms 66256 KB Output is correct
53 Correct 1507 ms 66264 KB Output is correct
54 Correct 1588 ms 66284 KB Output is correct
55 Correct 1552 ms 66332 KB Output is correct
56 Correct 1506 ms 66372 KB Output is correct
57 Correct 1523 ms 66300 KB Output is correct
58 Correct 1495 ms 66272 KB Output is correct
59 Correct 1522 ms 66356 KB Output is correct
60 Correct 1528 ms 66336 KB Output is correct
61 Correct 1504 ms 66240 KB Output is correct
62 Correct 1527 ms 66280 KB Output is correct
63 Correct 1525 ms 66244 KB Output is correct
64 Correct 1557 ms 66284 KB Output is correct
65 Correct 1533 ms 66216 KB Output is correct
66 Correct 1571 ms 66348 KB Output is correct
67 Correct 1592 ms 66360 KB Output is correct
68 Correct 1519 ms 66276 KB Output is correct
69 Correct 1563 ms 66284 KB Output is correct
70 Correct 1544 ms 66284 KB Output is correct
71 Correct 1572 ms 66332 KB Output is correct
72 Correct 1523 ms 66276 KB Output is correct
73 Correct 1539 ms 66348 KB Output is correct
74 Correct 1521 ms 66320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 3 ms 748 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 6 ms 724 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 5 ms 724 KB Output is correct
20 Correct 4 ms 724 KB Output is correct
21 Correct 6 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
23 Correct 5 ms 724 KB Output is correct
24 Correct 4 ms 724 KB Output is correct
25 Correct 6 ms 732 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 5 ms 724 KB Output is correct
37 Correct 6 ms 748 KB Output is correct
38 Correct 6 ms 744 KB Output is correct
39 Correct 5 ms 744 KB Output is correct
40 Correct 5 ms 724 KB Output is correct
41 Correct 5 ms 724 KB Output is correct
42 Correct 5 ms 724 KB Output is correct
43 Correct 5 ms 724 KB Output is correct
44 Correct 5 ms 744 KB Output is correct
45 Correct 5 ms 724 KB Output is correct
46 Correct 4 ms 724 KB Output is correct
47 Correct 6 ms 724 KB Output is correct
48 Correct 1725 ms 66284 KB Output is correct
49 Correct 1588 ms 66284 KB Output is correct
50 Correct 1570 ms 66284 KB Output is correct
51 Correct 1597 ms 66352 KB Output is correct
52 Correct 1588 ms 66284 KB Output is correct
53 Correct 1665 ms 66280 KB Output is correct
54 Correct 1657 ms 66352 KB Output is correct
55 Correct 1642 ms 66304 KB Output is correct
56 Correct 1642 ms 66336 KB Output is correct
57 Correct 1608 ms 66340 KB Output is correct
58 Correct 1547 ms 66356 KB Output is correct
59 Correct 1620 ms 66352 KB Output is correct
60 Correct 1643 ms 66340 KB Output is correct
61 Correct 1505 ms 66276 KB Output is correct
62 Correct 1505 ms 66300 KB Output is correct
63 Correct 1504 ms 66320 KB Output is correct
64 Correct 1508 ms 66284 KB Output is correct
65 Correct 1500 ms 66428 KB Output is correct
66 Correct 1517 ms 66356 KB Output is correct
67 Correct 1480 ms 66256 KB Output is correct
68 Correct 1507 ms 66264 KB Output is correct
69 Correct 1588 ms 66284 KB Output is correct
70 Correct 1552 ms 66332 KB Output is correct
71 Correct 1506 ms 66372 KB Output is correct
72 Correct 1523 ms 66300 KB Output is correct
73 Correct 1495 ms 66272 KB Output is correct
74 Correct 1522 ms 66356 KB Output is correct
75 Correct 1528 ms 66336 KB Output is correct
76 Correct 1504 ms 66240 KB Output is correct
77 Correct 1527 ms 66280 KB Output is correct
78 Correct 1525 ms 66244 KB Output is correct
79 Correct 1557 ms 66284 KB Output is correct
80 Correct 1533 ms 66216 KB Output is correct
81 Correct 1571 ms 66348 KB Output is correct
82 Correct 1592 ms 66360 KB Output is correct
83 Correct 1519 ms 66276 KB Output is correct
84 Correct 1563 ms 66284 KB Output is correct
85 Correct 1544 ms 66284 KB Output is correct
86 Correct 1572 ms 66332 KB Output is correct
87 Correct 1523 ms 66276 KB Output is correct
88 Correct 1539 ms 66348 KB Output is correct
89 Correct 1521 ms 66320 KB Output is correct
90 Correct 1541 ms 66372 KB Output is correct
91 Correct 1542 ms 66276 KB Output is correct
92 Correct 1538 ms 66388 KB Output is correct
93 Correct 1538 ms 66356 KB Output is correct
94 Correct 1544 ms 66328 KB Output is correct
95 Correct 1509 ms 66284 KB Output is correct
96 Correct 1510 ms 66308 KB Output is correct
97 Correct 1520 ms 66332 KB Output is correct
98 Correct 1502 ms 66296 KB Output is correct
99 Correct 1514 ms 66300 KB Output is correct
100 Runtime error 1092 ms 176120 KB Execution killed with signal 11
101 Halted 0 ms 0 KB -