답안 #317363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317363 2020-10-29T15:40:29 Z CaroLinda Bulldozer (JOI17_bulldozer) C++14
100 / 100
1330 ms 17128 KB
#include <bits/stdc++.h>
 
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x.size())
#define ll long long
 
const int MAXN = 2010 ;
 
using namespace std ;
 
struct Seg
{
	
	long long soma[MAXN*4] ;
	long long bestLeft[MAXN*4] ;
	long long bestRight[MAXN*4] ;
	long long bestSum[MAXN*4] ;
 
	int m(int l, int r ) { return (l+r)>>1 ; }
 
	void print(int pos, int l, int r ) 
	{

		if(l == r ) return (void)(printf("%lld ", soma[pos] ) ) ;
 
		print(pos<<1 , l, m(l,r) ) ;
		print(pos<<1|1 , m(l,r)+1, r ) ;
 
	}
 
 
	void upd(int pos, int l, int r, int k, long long val ) //vamos de seg de setar?
	{
		if( l == r ) 
		{
			soma[pos] = val ;
			bestLeft[pos] = bestRight[pos] = bestSum[pos] = max(val, 0LL ) ;
			return ;
		}
 
		if( k <= m(l,r) ) upd(pos<<1 , l , m(l,r) , k, val ) ;
		else upd(pos<<1|1 , m(l,r)+1, r, k, val ) ;
 
		soma[pos] = soma[pos<<1] + soma[pos<<1|1] ;
		bestLeft[pos] = max(bestLeft[pos<<1|1] , soma[pos<<1|1] + bestLeft[pos<<1] ) ;
		bestRight[pos] = max(bestRight[pos<<1], soma[pos<<1] + bestRight[pos<<1|1] ) ;
		bestSum[pos] = bestLeft[pos<<1] + bestRight[pos<<1|1] ;
 
		bestSum[pos] = max(bestSum[pos<<1] ,max(bestSum[pos] , bestSum[pos<<1|1] ) ) ;
 
	}
 
	long long getAns() { return bestSum[1] ; }
 
} seg ;
 
int n ;
int pos[MAXN] ;
long long x[MAXN], y[MAXN] ;
long long w[MAXN] ;
 
int getFakeQuadrant(int i, int j )
{
	
	if( x[i] > x[j] ) return 0 ;
	if(x[i] == x[j] ) return 1 ;
	return 2 ;
 
}
 
struct Event
{
 
	int i , j ;
 
	Event(int i = 0 , int j = 0 ) : i(i) , j(j) {}
	
	bool operator < (Event other) const 
	{
		
		/* Tenho certeza que:
			i) y[i] > y[j]
			ii) y[i] == y[j] && x[i] > x[j]
 
			O numerador sempre vai ser positivo ou zero
		*/
 
		pair<long long,long long> mySlope = make_pair(y[i]-y[j], x[i]-x[j] ) ;
		pair<long long,long long> otherSlope = make_pair(y[other.i]-y[other.j], x[other.i]-x[other.j] ) ;
 
		int myFakeQuadrant =  getFakeQuadrant(i,j) ;
		int otherFakeQuadrant = getFakeQuadrant(other.i , other.j ) ;
 
		if(myFakeQuadrant != otherFakeQuadrant ) 
			return myFakeQuadrant < otherFakeQuadrant ;
 
		//Remember the denominators can be negative
		//And, therefore, the comparison will be weird	
 
		if( mySlope.first * otherSlope.second == mySlope.second * otherSlope.first )
		{
			//This will work even if there isn't a slope at all

			if( mySlope.first == 0 )
				return make_pair( x[i] , x[j] ) > make_pair( x[other.i] , x[other.j] ) ;

			return make_pair(y[i], y[j] ) > make_pair(y[other.i],  y[other.j] ) ;
		}
 
		if(mySlope.second < 0 ) 
		{
			mySlope.first = -mySlope.first ;
			mySlope.second = -mySlope.second ;
		}
		if(otherSlope.second < 0 )
		{
			otherSlope.first = -otherSlope.first ;
			otherSlope.second = -otherSlope.second ;
		}
 
		return mySlope.first * otherSlope.second < mySlope.second * otherSlope.first ;
		
	}
} ;
 
bool isEqual(Event a, Event b )
{
 
	pair<long long,long long> slope_a = make_pair( y[a.i] - y[a.j] , x[a.i] - x[a.j] ) ;
	pair<long long,long long> slope_b = make_pair( y[b.i] - y[b.j], x[b.i] - x[b.j] ) ;
 
	if( getFakeQuadrant(a.i, a.j ) != getFakeQuadrant(b.i, b.j ) )
		return false ;
 
	return slope_a.first * slope_b.second == slope_a.second * slope_b.first ;
 
}
     
int main()
{
	scanf("%d", &n ) ;
	for(int i = 1 ; i <= n ; i++ ) scanf("%lld %lld %lld", &x[i], &y[i] , &w[i] ) ;
 
	vector<int> initialSort(n) ;
	iota(all(initialSort),1) ;
	sort(all(initialSort), [&](int i, int j ) { 
	
		if( y[i] != y[j] ) return y[i] > y[j] ;
		return x[i] > x[j] ; 
 
	} ) ;
 
 //	for(int i = 0 ; i < n ; i++ ) cout << char(initialSort[i] + 'A' - 1 ) << " " ;
// 	cout << endl ;
 
	vector<Event> sweep ;
	
	for(int i = 0 ; i < n ; i++ ) pos[ initialSort[i] ] = i+1 ;
	
	for(int i = 0 ; i < n ; i++ )
		for(int j = i+1 ; j < n ; j++ )
			sweep.push_back(Event(initialSort[i],initialSort[j]) ) ;
 
	sort(all(sweep));
	//Depois eu crio a seg, vamos tentar entender os eventos primeiro
 
//	for(auto e : sweep ) cout << char(e.i + 'A'-1) << " " << char(e.j+'A'-1) << endl ;
 
	for(int i = 1 ; i <= n ; i++ ) seg.upd(1,1,n, pos[i] , w[i] ) ;
	
	long long ans = 0LL ;
	ans = max(ans, seg.getAns() ) ;
 
	for(int i = 0 ; i < sz(sweep ) ;  )
	{
		//initiating batch process
		int j = i ;
 
		while( j < sz(sweep) && isEqual(sweep[i], sweep[j] ) )
		{
			int u = sweep[j].i ;
			int v = sweep[j].j ;
 
			seg.upd(1 , 1 , n , pos[u] , w[v] ) ;
			seg.upd(1,1,n, pos[v], w[u] ) ;
 
			swap(pos[u], pos[v] ) ;
 
			j++ ;
		}		
 
		i = j ;
 
		/*cout << "After some lines"<< endl ;
		seg.print(1,1,n) ;
		cout << endl ; */
 
		ans = max(ans, seg.getAns() ) ;
	}
 
	printf("%lld\n", ans ) ;
 
}

Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:141:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  141 |  scanf("%d", &n ) ;
      |  ~~~~~^~~~~~~~~~~
bulldozer.cpp:142:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  142 |  for(int i = 1 ; i <= n ; i++ ) scanf("%lld %lld %lld", &x[i], &y[i] , &w[i] ) ;
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 2 ms 416 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 544 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 416 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 544 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 416 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1081 ms 17000 KB Output is correct
34 Correct 1060 ms 17128 KB Output is correct
35 Correct 1069 ms 17000 KB Output is correct
36 Correct 1099 ms 17000 KB Output is correct
37 Correct 1045 ms 17000 KB Output is correct
38 Correct 1096 ms 17000 KB Output is correct
39 Correct 1046 ms 17000 KB Output is correct
40 Correct 1091 ms 17128 KB Output is correct
41 Correct 1071 ms 17000 KB Output is correct
42 Correct 1073 ms 17000 KB Output is correct
43 Correct 1018 ms 17000 KB Output is correct
44 Correct 1028 ms 17000 KB Output is correct
45 Correct 1016 ms 17000 KB Output is correct
46 Correct 1045 ms 17000 KB Output is correct
47 Correct 1022 ms 17000 KB Output is correct
48 Correct 1046 ms 17000 KB Output is correct
49 Correct 1055 ms 17000 KB Output is correct
50 Correct 1049 ms 17000 KB Output is correct
51 Correct 1059 ms 17000 KB Output is correct
52 Correct 1054 ms 17000 KB Output is correct
53 Correct 1048 ms 17000 KB Output is correct
54 Correct 1073 ms 17000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 544 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 416 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1081 ms 17000 KB Output is correct
34 Correct 1060 ms 17128 KB Output is correct
35 Correct 1069 ms 17000 KB Output is correct
36 Correct 1099 ms 17000 KB Output is correct
37 Correct 1045 ms 17000 KB Output is correct
38 Correct 1096 ms 17000 KB Output is correct
39 Correct 1046 ms 17000 KB Output is correct
40 Correct 1091 ms 17128 KB Output is correct
41 Correct 1071 ms 17000 KB Output is correct
42 Correct 1073 ms 17000 KB Output is correct
43 Correct 1018 ms 17000 KB Output is correct
44 Correct 1028 ms 17000 KB Output is correct
45 Correct 1016 ms 17000 KB Output is correct
46 Correct 1045 ms 17000 KB Output is correct
47 Correct 1022 ms 17000 KB Output is correct
48 Correct 1046 ms 17000 KB Output is correct
49 Correct 1055 ms 17000 KB Output is correct
50 Correct 1049 ms 17000 KB Output is correct
51 Correct 1059 ms 17000 KB Output is correct
52 Correct 1054 ms 17000 KB Output is correct
53 Correct 1048 ms 17000 KB Output is correct
54 Correct 1073 ms 17000 KB Output is correct
55 Correct 1061 ms 16992 KB Output is correct
56 Correct 1103 ms 17128 KB Output is correct
57 Correct 1059 ms 17000 KB Output is correct
58 Correct 1064 ms 17000 KB Output is correct
59 Correct 1096 ms 17000 KB Output is correct
60 Correct 1059 ms 16936 KB Output is correct
61 Correct 1098 ms 17000 KB Output is correct
62 Correct 1119 ms 17000 KB Output is correct
63 Correct 1094 ms 17000 KB Output is correct
64 Correct 1060 ms 17000 KB Output is correct
65 Correct 1094 ms 17000 KB Output is correct
66 Correct 1072 ms 17000 KB Output is correct
67 Correct 1072 ms 17128 KB Output is correct
68 Correct 1073 ms 17128 KB Output is correct
69 Correct 1081 ms 17000 KB Output is correct
70 Correct 1064 ms 17000 KB Output is correct
71 Correct 1076 ms 17000 KB Output is correct
72 Correct 1132 ms 17128 KB Output is correct
73 Correct 1101 ms 17000 KB Output is correct
74 Correct 1081 ms 17000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 2 ms 416 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 3 ms 544 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 416 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 2 ms 512 KB Output is correct
48 Correct 1081 ms 17000 KB Output is correct
49 Correct 1060 ms 17128 KB Output is correct
50 Correct 1069 ms 17000 KB Output is correct
51 Correct 1099 ms 17000 KB Output is correct
52 Correct 1045 ms 17000 KB Output is correct
53 Correct 1096 ms 17000 KB Output is correct
54 Correct 1046 ms 17000 KB Output is correct
55 Correct 1091 ms 17128 KB Output is correct
56 Correct 1071 ms 17000 KB Output is correct
57 Correct 1073 ms 17000 KB Output is correct
58 Correct 1018 ms 17000 KB Output is correct
59 Correct 1028 ms 17000 KB Output is correct
60 Correct 1016 ms 17000 KB Output is correct
61 Correct 1045 ms 17000 KB Output is correct
62 Correct 1022 ms 17000 KB Output is correct
63 Correct 1046 ms 17000 KB Output is correct
64 Correct 1055 ms 17000 KB Output is correct
65 Correct 1049 ms 17000 KB Output is correct
66 Correct 1059 ms 17000 KB Output is correct
67 Correct 1054 ms 17000 KB Output is correct
68 Correct 1048 ms 17000 KB Output is correct
69 Correct 1073 ms 17000 KB Output is correct
70 Correct 1061 ms 16992 KB Output is correct
71 Correct 1103 ms 17128 KB Output is correct
72 Correct 1059 ms 17000 KB Output is correct
73 Correct 1064 ms 17000 KB Output is correct
74 Correct 1096 ms 17000 KB Output is correct
75 Correct 1059 ms 16936 KB Output is correct
76 Correct 1098 ms 17000 KB Output is correct
77 Correct 1119 ms 17000 KB Output is correct
78 Correct 1094 ms 17000 KB Output is correct
79 Correct 1060 ms 17000 KB Output is correct
80 Correct 1094 ms 17000 KB Output is correct
81 Correct 1072 ms 17000 KB Output is correct
82 Correct 1072 ms 17128 KB Output is correct
83 Correct 1073 ms 17128 KB Output is correct
84 Correct 1081 ms 17000 KB Output is correct
85 Correct 1064 ms 17000 KB Output is correct
86 Correct 1076 ms 17000 KB Output is correct
87 Correct 1132 ms 17128 KB Output is correct
88 Correct 1101 ms 17000 KB Output is correct
89 Correct 1081 ms 17000 KB Output is correct
90 Correct 1100 ms 17000 KB Output is correct
91 Correct 1083 ms 17000 KB Output is correct
92 Correct 1114 ms 17000 KB Output is correct
93 Correct 1061 ms 17000 KB Output is correct
94 Correct 1061 ms 17000 KB Output is correct
95 Correct 1149 ms 17000 KB Output is correct
96 Correct 1100 ms 17000 KB Output is correct
97 Correct 1108 ms 17000 KB Output is correct
98 Correct 1153 ms 17000 KB Output is correct
99 Correct 1104 ms 17000 KB Output is correct
100 Correct 1016 ms 17000 KB Output is correct
101 Correct 1170 ms 17000 KB Output is correct
102 Correct 1002 ms 16968 KB Output is correct
103 Correct 1055 ms 17000 KB Output is correct
104 Correct 947 ms 16948 KB Output is correct
105 Correct 1014 ms 17032 KB Output is correct
106 Correct 1036 ms 17000 KB Output is correct
107 Correct 1036 ms 17000 KB Output is correct
108 Correct 1134 ms 17000 KB Output is correct
109 Correct 1092 ms 17000 KB Output is correct
110 Correct 963 ms 17000 KB Output is correct
111 Correct 1030 ms 17000 KB Output is correct
112 Correct 949 ms 17000 KB Output is correct
113 Correct 1006 ms 17000 KB Output is correct
114 Correct 1042 ms 17000 KB Output is correct
115 Correct 1330 ms 16976 KB Output is correct
116 Correct 1101 ms 16992 KB Output is correct
117 Correct 1048 ms 17000 KB Output is correct
118 Correct 1109 ms 17000 KB Output is correct
119 Correct 1070 ms 17032 KB Output is correct
120 Correct 1 ms 384 KB Output is correct
121 Correct 1 ms 384 KB Output is correct
122 Correct 1222 ms 17000 KB Output is correct
123 Correct 1066 ms 17000 KB Output is correct
124 Correct 1051 ms 17000 KB Output is correct
125 Correct 1065 ms 17000 KB Output is correct
126 Correct 1116 ms 17000 KB Output is correct
127 Correct 1262 ms 16992 KB Output is correct
128 Correct 1073 ms 17000 KB Output is correct
129 Correct 1266 ms 17000 KB Output is correct
130 Correct 1212 ms 16976 KB Output is correct
131 Correct 1141 ms 17000 KB Output is correct
132 Correct 1070 ms 17000 KB Output is correct
133 Correct 1175 ms 17000 KB Output is correct