답안 #36073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36073 2017-12-05T05:54:43 Z huynd2001 Bulldozer (JOI17_bulldozer) C++14
100 / 100
1797 ms 160412 KB
/*huypheu
15
10 3 30
5 10 -17
4 -5 14
0 -3 -9
-2 3 17
6 9 -19
-9 -6 -14
-2 -3 10
-3 -3 30
8 1 -28
9 -9 -5
7 -5 -24
-8 -10 5
-7 2 20
10 -3 -13
*/

//https://oj.uz/problem/view/JOI17_bulldozer
#include <bits/stdc++.h>
#define int long long
#define oo (LLONG_MAX/2)
using namespace std;

struct ite
{
	int val,lef,rig,tot;
}it[100007];

int x[20007],y[20007];
int pos[20007];
int c[20007],ar[20007];

void build(int node,int l,int r)
{
	if(l>r) return ;
	if(l==r)
	{
		it[node].lef=max(0ll,ar[l]);
		it[node].rig=max(0ll,ar[l]);
		it[node].tot=ar[l];
		it[node].val=max(0ll,ar[l]);
		return ;
	}
	int mid=(l+r)/2;
	build(node*2,l,mid);
	build(node*2+1,mid+1,r);
	it[node].lef=max(it[node*2].lef,it[node*2].tot+it[node*2+1].lef);
	it[node].rig=max(it[node*2+1].rig,it[node*2+1].tot+it[node*2].rig);
	it[node].tot=it[node*2].tot+it[node*2+1].tot;
	it[node].val=max(it[node*2].rig+it[node*2+1].lef,max(it[node*2].val,it[node*2+1].val));
	return ;
}

void update(int node,int l,int r,int m,int p)
{
	if(l>r) return ;
	if(l==r)
	{
		it[node].lef=max(0ll,p);
		it[node].rig=max(0ll,p);
		it[node].tot=p;
		it[node].val=max(0ll,p);
		return ;
	}
	int mid=(l+r)/2;
	if(m<=mid) update(node*2,l,mid,m,p); else update(node*2+1,mid+1,r,m,p);
	it[node].lef=max(it[node*2].lef,it[node*2].tot+it[node*2+1].lef);
	it[node].rig=max(it[node*2+1].rig,it[node*2+1].tot+it[node*2].rig);
	it[node].tot=it[node*2].tot+it[node*2+1].tot;
	it[node].val=max(it[node*2].rig+it[node*2+1].lef,max(it[node*2].val,it[node*2+1].val));
	return ;
}
	vector <int> vo;
	vector <pair<pair<int,int> ,pair<int,int> > > va;
double cura,curb;
vector <pair<int,int> > vnone;

map <pair<int,int> ,int> mapu;
vector <pair<int,int> > vip[4000007];

pair<int,int> fap(int a,int b)
{
	if(b==0) return make_pair(1,0);
	int k=__gcd(a,b);
	a/=k;
	b/=k;
	if(b<0) b=-b,a=-a;
	return make_pair(a,b);
}

bool kem_hon(int a,int b)
{
	if(x[a]!=x[b]) return (x[a]<x[b]); else return (y[a]<y[b]);
}

bool cmp(pair<int,int> a,pair<int,int> b)
{
	return (a.first*b.second>b.first*a.second);
}

bool cmp2(int a,int b)
{
	return ((double)y[a]/(double)cura-(double)x[a]/(double)curb<(double)y[b]/(double)cura-(double)x[b]/(double)curb);
}

bool cmp3(pair<int,int> a,pair<int,int> b)
{
	if(a.first!=b.first) return kem_hon(a.first,b.first); else return kem_hon(a.second,b.second);
}

bool cmp4(pair<pair<int,int>,pair<int,int> > x,pair<pair<int,int>,pair<int,int> > y)
{
	if(x.first!=y.first) return cmp(x.first,y.first); else return cmp3(x.second,y.second);
}

int n;

void swapy(int a,int b)
{
	int c,d;
	c=pos[a],d=pos[b];
	update(1,1,n,d,ar[c]);
	update(1,1,n,c,ar[d]);
	swap(ar[c],ar[d]);
	swap(pos[a],pos[b]);
	swap(vo[pos[a]-1],vo[pos[b]-1]);
	return ;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> x[i] >> y[i] >> c[i];
	}
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			pair<int,int> s;
			s=fap((y[j]-y[i]),(x[j]-x[i]));
			int si=i,sj=j;
			if(kem_hon(sj,si)) swap(si,sj);
			va.push_back(make_pair(s,make_pair(si,sj)));
		}
	}
	sort(va.begin(),va.end(),cmp4);
	// for(int i=0;i<va.size();i++) cout << va[i].first.first << "/" << va[i].first.second << endl;
	for(int i=1;i<=n;i++) vo.push_back(i);
		cura=1,curb=0;
	if(va.size()>0) cura=va[va.size()-1].first.first,curb=va[va.size()-1].first.second;
	// cout << cura << "/" << curb << endl;
	if(curb==0) curb=1; else cura--;
	sort(vo.begin(),vo.end(),cmp2);
	for(int i=0;i<vo.size();i++)
	{
		pos[vo[i]]=i+1;
		ar[i+1]=c[vo[i]];
	}
	build(1,1,n);
	int ans=it[1].val;
	// for(int i=0;i<vo.size();i++) cout << vo[i] << " ";cout << endl;
	for(int i=0;i<va.size();i++)
	{
		swapy(va[i].second.first,va[i].second.second);
		// for(int i=0;i<vo.size();i++) cout << vo[i] << " ";cout << endl;
		if(i==va.size()-1 || va[i].first!=va[i+1].first) ans=max(ans,it[1].val);
	}
	cout << ans << endl;
	return 0;
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:160:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<vo.size();i++)
              ~^~~~~~~~~~
bulldozer.cpp:168:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<va.size();i++)
              ~^~~~~~~~~~
bulldozer.cpp:172:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i==va.size()-1 || va[i].first!=va[i+1].first) ans=max(ans,it[1].val);
      ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 94816 KB Output is correct
2 Correct 88 ms 94716 KB Output is correct
3 Correct 95 ms 94624 KB Output is correct
4 Correct 87 ms 94644 KB Output is correct
5 Correct 84 ms 94632 KB Output is correct
6 Correct 84 ms 94712 KB Output is correct
7 Correct 82 ms 94712 KB Output is correct
8 Correct 83 ms 94712 KB Output is correct
9 Correct 82 ms 94708 KB Output is correct
10 Correct 89 ms 94712 KB Output is correct
11 Correct 81 ms 94328 KB Output is correct
12 Correct 81 ms 94328 KB Output is correct
13 Correct 82 ms 94328 KB Output is correct
14 Correct 81 ms 94232 KB Output is correct
15 Correct 81 ms 94300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 94632 KB Output is correct
2 Correct 84 ms 94752 KB Output is correct
3 Correct 86 ms 94712 KB Output is correct
4 Correct 84 ms 94716 KB Output is correct
5 Correct 84 ms 94652 KB Output is correct
6 Correct 85 ms 94712 KB Output is correct
7 Correct 87 ms 94696 KB Output is correct
8 Correct 89 ms 94676 KB Output is correct
9 Correct 90 ms 94712 KB Output is correct
10 Correct 85 ms 94684 KB Output is correct
11 Correct 84 ms 94328 KB Output is correct
12 Correct 82 ms 94328 KB Output is correct
13 Correct 80 ms 94328 KB Output is correct
14 Correct 85 ms 94332 KB Output is correct
15 Correct 82 ms 94328 KB Output is correct
16 Correct 84 ms 94268 KB Output is correct
17 Correct 81 ms 94328 KB Output is correct
18 Correct 80 ms 94308 KB Output is correct
19 Correct 82 ms 94332 KB Output is correct
20 Correct 83 ms 94308 KB Output is correct
21 Correct 84 ms 94712 KB Output is correct
22 Correct 85 ms 94712 KB Output is correct
23 Correct 84 ms 94712 KB Output is correct
24 Correct 83 ms 94712 KB Output is correct
25 Correct 84 ms 94652 KB Output is correct
26 Correct 87 ms 94712 KB Output is correct
27 Correct 84 ms 94712 KB Output is correct
28 Correct 85 ms 94712 KB Output is correct
29 Correct 85 ms 94680 KB Output is correct
30 Correct 87 ms 94712 KB Output is correct
31 Correct 85 ms 94728 KB Output is correct
32 Correct 85 ms 94712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 94632 KB Output is correct
2 Correct 84 ms 94752 KB Output is correct
3 Correct 86 ms 94712 KB Output is correct
4 Correct 84 ms 94716 KB Output is correct
5 Correct 84 ms 94652 KB Output is correct
6 Correct 85 ms 94712 KB Output is correct
7 Correct 87 ms 94696 KB Output is correct
8 Correct 89 ms 94676 KB Output is correct
9 Correct 90 ms 94712 KB Output is correct
10 Correct 85 ms 94684 KB Output is correct
11 Correct 84 ms 94328 KB Output is correct
12 Correct 82 ms 94328 KB Output is correct
13 Correct 80 ms 94328 KB Output is correct
14 Correct 85 ms 94332 KB Output is correct
15 Correct 82 ms 94328 KB Output is correct
16 Correct 84 ms 94268 KB Output is correct
17 Correct 81 ms 94328 KB Output is correct
18 Correct 80 ms 94308 KB Output is correct
19 Correct 82 ms 94332 KB Output is correct
20 Correct 83 ms 94308 KB Output is correct
21 Correct 84 ms 94712 KB Output is correct
22 Correct 85 ms 94712 KB Output is correct
23 Correct 84 ms 94712 KB Output is correct
24 Correct 83 ms 94712 KB Output is correct
25 Correct 84 ms 94652 KB Output is correct
26 Correct 87 ms 94712 KB Output is correct
27 Correct 84 ms 94712 KB Output is correct
28 Correct 85 ms 94712 KB Output is correct
29 Correct 85 ms 94680 KB Output is correct
30 Correct 87 ms 94712 KB Output is correct
31 Correct 85 ms 94728 KB Output is correct
32 Correct 85 ms 94712 KB Output is correct
33 Correct 1687 ms 160156 KB Output is correct
34 Correct 1760 ms 160336 KB Output is correct
35 Correct 1757 ms 160156 KB Output is correct
36 Correct 1702 ms 160156 KB Output is correct
37 Correct 1713 ms 160244 KB Output is correct
38 Correct 1726 ms 160104 KB Output is correct
39 Correct 1740 ms 160156 KB Output is correct
40 Correct 1753 ms 160156 KB Output is correct
41 Correct 1727 ms 160156 KB Output is correct
42 Correct 1797 ms 160136 KB Output is correct
43 Correct 1578 ms 160196 KB Output is correct
44 Correct 1581 ms 160100 KB Output is correct
45 Correct 1570 ms 160156 KB Output is correct
46 Correct 1631 ms 160156 KB Output is correct
47 Correct 1606 ms 160164 KB Output is correct
48 Correct 1609 ms 160180 KB Output is correct
49 Correct 1607 ms 160300 KB Output is correct
50 Correct 1612 ms 160284 KB Output is correct
51 Correct 1611 ms 160112 KB Output is correct
52 Correct 1587 ms 160160 KB Output is correct
53 Correct 1567 ms 160204 KB Output is correct
54 Correct 1598 ms 160092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 94632 KB Output is correct
2 Correct 84 ms 94752 KB Output is correct
3 Correct 86 ms 94712 KB Output is correct
4 Correct 84 ms 94716 KB Output is correct
5 Correct 84 ms 94652 KB Output is correct
6 Correct 85 ms 94712 KB Output is correct
7 Correct 87 ms 94696 KB Output is correct
8 Correct 89 ms 94676 KB Output is correct
9 Correct 90 ms 94712 KB Output is correct
10 Correct 85 ms 94684 KB Output is correct
11 Correct 84 ms 94328 KB Output is correct
12 Correct 82 ms 94328 KB Output is correct
13 Correct 80 ms 94328 KB Output is correct
14 Correct 85 ms 94332 KB Output is correct
15 Correct 82 ms 94328 KB Output is correct
16 Correct 84 ms 94268 KB Output is correct
17 Correct 81 ms 94328 KB Output is correct
18 Correct 80 ms 94308 KB Output is correct
19 Correct 82 ms 94332 KB Output is correct
20 Correct 83 ms 94308 KB Output is correct
21 Correct 84 ms 94712 KB Output is correct
22 Correct 85 ms 94712 KB Output is correct
23 Correct 84 ms 94712 KB Output is correct
24 Correct 83 ms 94712 KB Output is correct
25 Correct 84 ms 94652 KB Output is correct
26 Correct 87 ms 94712 KB Output is correct
27 Correct 84 ms 94712 KB Output is correct
28 Correct 85 ms 94712 KB Output is correct
29 Correct 85 ms 94680 KB Output is correct
30 Correct 87 ms 94712 KB Output is correct
31 Correct 85 ms 94728 KB Output is correct
32 Correct 85 ms 94712 KB Output is correct
33 Correct 1687 ms 160156 KB Output is correct
34 Correct 1760 ms 160336 KB Output is correct
35 Correct 1757 ms 160156 KB Output is correct
36 Correct 1702 ms 160156 KB Output is correct
37 Correct 1713 ms 160244 KB Output is correct
38 Correct 1726 ms 160104 KB Output is correct
39 Correct 1740 ms 160156 KB Output is correct
40 Correct 1753 ms 160156 KB Output is correct
41 Correct 1727 ms 160156 KB Output is correct
42 Correct 1797 ms 160136 KB Output is correct
43 Correct 1578 ms 160196 KB Output is correct
44 Correct 1581 ms 160100 KB Output is correct
45 Correct 1570 ms 160156 KB Output is correct
46 Correct 1631 ms 160156 KB Output is correct
47 Correct 1606 ms 160164 KB Output is correct
48 Correct 1609 ms 160180 KB Output is correct
49 Correct 1607 ms 160300 KB Output is correct
50 Correct 1612 ms 160284 KB Output is correct
51 Correct 1611 ms 160112 KB Output is correct
52 Correct 1587 ms 160160 KB Output is correct
53 Correct 1567 ms 160204 KB Output is correct
54 Correct 1598 ms 160092 KB Output is correct
55 Correct 1690 ms 160120 KB Output is correct
56 Correct 1699 ms 160228 KB Output is correct
57 Correct 1722 ms 160124 KB Output is correct
58 Correct 1684 ms 160208 KB Output is correct
59 Correct 1685 ms 160248 KB Output is correct
60 Correct 1693 ms 160164 KB Output is correct
61 Correct 1685 ms 160304 KB Output is correct
62 Correct 1680 ms 160412 KB Output is correct
63 Correct 1714 ms 160084 KB Output is correct
64 Correct 1736 ms 160236 KB Output is correct
65 Correct 1694 ms 160156 KB Output is correct
66 Correct 1764 ms 160216 KB Output is correct
67 Correct 1761 ms 160128 KB Output is correct
68 Correct 1704 ms 160104 KB Output is correct
69 Correct 1732 ms 160164 KB Output is correct
70 Correct 1724 ms 160328 KB Output is correct
71 Correct 1741 ms 160212 KB Output is correct
72 Correct 1708 ms 160096 KB Output is correct
73 Correct 1759 ms 160148 KB Output is correct
74 Correct 1682 ms 160192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 94816 KB Output is correct
2 Correct 88 ms 94716 KB Output is correct
3 Correct 95 ms 94624 KB Output is correct
4 Correct 87 ms 94644 KB Output is correct
5 Correct 84 ms 94632 KB Output is correct
6 Correct 84 ms 94712 KB Output is correct
7 Correct 82 ms 94712 KB Output is correct
8 Correct 83 ms 94712 KB Output is correct
9 Correct 82 ms 94708 KB Output is correct
10 Correct 89 ms 94712 KB Output is correct
11 Correct 81 ms 94328 KB Output is correct
12 Correct 81 ms 94328 KB Output is correct
13 Correct 82 ms 94328 KB Output is correct
14 Correct 81 ms 94232 KB Output is correct
15 Correct 81 ms 94300 KB Output is correct
16 Correct 83 ms 94632 KB Output is correct
17 Correct 84 ms 94752 KB Output is correct
18 Correct 86 ms 94712 KB Output is correct
19 Correct 84 ms 94716 KB Output is correct
20 Correct 84 ms 94652 KB Output is correct
21 Correct 85 ms 94712 KB Output is correct
22 Correct 87 ms 94696 KB Output is correct
23 Correct 89 ms 94676 KB Output is correct
24 Correct 90 ms 94712 KB Output is correct
25 Correct 85 ms 94684 KB Output is correct
26 Correct 84 ms 94328 KB Output is correct
27 Correct 82 ms 94328 KB Output is correct
28 Correct 80 ms 94328 KB Output is correct
29 Correct 85 ms 94332 KB Output is correct
30 Correct 82 ms 94328 KB Output is correct
31 Correct 84 ms 94268 KB Output is correct
32 Correct 81 ms 94328 KB Output is correct
33 Correct 80 ms 94308 KB Output is correct
34 Correct 82 ms 94332 KB Output is correct
35 Correct 83 ms 94308 KB Output is correct
36 Correct 84 ms 94712 KB Output is correct
37 Correct 85 ms 94712 KB Output is correct
38 Correct 84 ms 94712 KB Output is correct
39 Correct 83 ms 94712 KB Output is correct
40 Correct 84 ms 94652 KB Output is correct
41 Correct 87 ms 94712 KB Output is correct
42 Correct 84 ms 94712 KB Output is correct
43 Correct 85 ms 94712 KB Output is correct
44 Correct 85 ms 94680 KB Output is correct
45 Correct 87 ms 94712 KB Output is correct
46 Correct 85 ms 94728 KB Output is correct
47 Correct 85 ms 94712 KB Output is correct
48 Correct 1687 ms 160156 KB Output is correct
49 Correct 1760 ms 160336 KB Output is correct
50 Correct 1757 ms 160156 KB Output is correct
51 Correct 1702 ms 160156 KB Output is correct
52 Correct 1713 ms 160244 KB Output is correct
53 Correct 1726 ms 160104 KB Output is correct
54 Correct 1740 ms 160156 KB Output is correct
55 Correct 1753 ms 160156 KB Output is correct
56 Correct 1727 ms 160156 KB Output is correct
57 Correct 1797 ms 160136 KB Output is correct
58 Correct 1578 ms 160196 KB Output is correct
59 Correct 1581 ms 160100 KB Output is correct
60 Correct 1570 ms 160156 KB Output is correct
61 Correct 1631 ms 160156 KB Output is correct
62 Correct 1606 ms 160164 KB Output is correct
63 Correct 1609 ms 160180 KB Output is correct
64 Correct 1607 ms 160300 KB Output is correct
65 Correct 1612 ms 160284 KB Output is correct
66 Correct 1611 ms 160112 KB Output is correct
67 Correct 1587 ms 160160 KB Output is correct
68 Correct 1567 ms 160204 KB Output is correct
69 Correct 1598 ms 160092 KB Output is correct
70 Correct 1690 ms 160120 KB Output is correct
71 Correct 1699 ms 160228 KB Output is correct
72 Correct 1722 ms 160124 KB Output is correct
73 Correct 1684 ms 160208 KB Output is correct
74 Correct 1685 ms 160248 KB Output is correct
75 Correct 1693 ms 160164 KB Output is correct
76 Correct 1685 ms 160304 KB Output is correct
77 Correct 1680 ms 160412 KB Output is correct
78 Correct 1714 ms 160084 KB Output is correct
79 Correct 1736 ms 160236 KB Output is correct
80 Correct 1694 ms 160156 KB Output is correct
81 Correct 1764 ms 160216 KB Output is correct
82 Correct 1761 ms 160128 KB Output is correct
83 Correct 1704 ms 160104 KB Output is correct
84 Correct 1732 ms 160164 KB Output is correct
85 Correct 1724 ms 160328 KB Output is correct
86 Correct 1741 ms 160212 KB Output is correct
87 Correct 1708 ms 160096 KB Output is correct
88 Correct 1759 ms 160148 KB Output is correct
89 Correct 1682 ms 160192 KB Output is correct
90 Correct 1698 ms 160128 KB Output is correct
91 Correct 1744 ms 160116 KB Output is correct
92 Correct 1703 ms 160156 KB Output is correct
93 Correct 1715 ms 160260 KB Output is correct
94 Correct 1698 ms 160188 KB Output is correct
95 Correct 1708 ms 160188 KB Output is correct
96 Correct 1734 ms 160200 KB Output is correct
97 Correct 1708 ms 160108 KB Output is correct
98 Correct 1700 ms 160096 KB Output is correct
99 Correct 1712 ms 160160 KB Output is correct
100 Correct 1134 ms 160076 KB Output is correct
101 Correct 1146 ms 160128 KB Output is correct
102 Correct 1181 ms 160144 KB Output is correct
103 Correct 1150 ms 160204 KB Output is correct
104 Correct 1121 ms 160240 KB Output is correct
105 Correct 1154 ms 160132 KB Output is correct
106 Correct 1147 ms 160188 KB Output is correct
107 Correct 1155 ms 160176 KB Output is correct
108 Correct 1158 ms 160096 KB Output is correct
109 Correct 1189 ms 160264 KB Output is correct
110 Correct 1440 ms 160156 KB Output is correct
111 Correct 1348 ms 160180 KB Output is correct
112 Correct 1362 ms 160108 KB Output is correct
113 Correct 1365 ms 160144 KB Output is correct
114 Correct 1362 ms 160268 KB Output is correct
115 Correct 1398 ms 160152 KB Output is correct
116 Correct 1413 ms 160104 KB Output is correct
117 Correct 1381 ms 160136 KB Output is correct
118 Correct 1397 ms 160108 KB Output is correct
119 Correct 1441 ms 160104 KB Output is correct
120 Correct 90 ms 94212 KB Output is correct
121 Correct 86 ms 94328 KB Output is correct
122 Correct 1407 ms 160156 KB Output is correct
123 Correct 1433 ms 160188 KB Output is correct
124 Correct 1410 ms 160188 KB Output is correct
125 Correct 1469 ms 160300 KB Output is correct
126 Correct 1394 ms 160216 KB Output is correct
127 Correct 1396 ms 160156 KB Output is correct
128 Correct 1434 ms 160160 KB Output is correct
129 Correct 1466 ms 160156 KB Output is correct
130 Correct 1467 ms 160132 KB Output is correct
131 Correct 1425 ms 160096 KB Output is correct
132 Correct 1481 ms 160152 KB Output is correct
133 Correct 1481 ms 160084 KB Output is correct