Submission #294217

# Submission time Handle Problem Language Result Execution time Memory
294217 2020-09-08T17:17:22 Z patrikpavic2 Bulldozer (JOI17_bulldozer) C++17
100 / 100
1915 ms 48104 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef pair < int, int > pii;
typedef pair < int, int > pt;
typedef long long ll;

const int N = 2e3 + 50;
const int M = N * N / 2LL;
const int OFF = (1 << 11);

bool par(pt A, pt B, pt C, pt D){
	return (ll)(A.X - B.X) * (C.Y - D.Y) == (ll)(C.X - D.X) * (A.Y - B.Y);
}

ll ccw(pt A, pt B, pt C){
	return (ll)A.X * (B.Y - C.Y) + (ll)B.X * (C.Y - A.Y) + (ll)C.X * (A.Y - B.Y);
}

pt sm[M], toc[N], ISH = {0, 0};
int pr[M], dr[M], pos[N], rd[N], duz[M], V[N];
int n, m;

inline bool cmp(int i, int j){
	return ccw(sm[i], ISH, sm[j]) < 0;
}

inline bool cmp2(int i, int j){
	if(toc[i].Y == toc[j].Y)
		return toc[i].X > toc[j].X;
	return toc[i].Y < toc[j].Y;
}

inline bool cmp3(int i, int j){
	return pos[i] < pos[j];
}

struct node{
	ll sol, L, R, sve;
	node(){
		sol = 0; L = 0; R = 0; sve = 0;
	}
	node(int x){
		sol = max(x, 0); L = sol; R = sol; sve = x;
	}
};

node T[2 * OFF];

inline node mrg(const node &A, const node &B){
	node C;
	C.sol = max(max(A.sol, B.sol), A.R + B.L);
	C.sve = A.sve + B.sve;
	C.L = max(A.L, A.sve + B.L);
	C.R = max(B.R, B.sve + A.R);
	return C;
};

void update(int i, int x){
	i += OFF;
	T[i] = node(x);
	for(i /= 2; i ; i /= 2)
		T[i] = mrg(T[2 * i], T[2 * i + 1]);
}

inline void obrni(int l, int r){
	for(;l < r;l++,r--){
		swap(rd[l], rd[r]);
		swap(pos[rd[l]], pos[rd[r]]);
		update(l, V[rd[l]]);
		update(r, V[rd[r]]);
	}
}

int main(){	
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d%d%d", &toc[i].X, &toc[i].Y, V + i);
		rd[i] = i;
	}
	sort(rd, rd + n, cmp2);
	for(int i = 0;i < n;i++){
		pos[rd[i]] = i;
		update(i, V[rd[i]]);
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < i;j++){
			pr[m] = rd[i];
			dr[m] = rd[j];
			sm[m] = {toc[pr[m]].X - toc[dr[m]].X, toc[pr[m]].Y - toc[dr[m]].Y};
			duz[m] = m; m++;
		}
	}
	sort(duz, duz + m, cmp);
	ll ans = T[1].sol;
	for(int i = 0;i < m;){
		int j = i;
		while(j < m && ccw(sm[duz[i]], ISH, sm[duz[j]]) == 0){
			//printf("sm[ %d ] = {%d %d}\n", duz[j], sm[duz[j]].X, sm[duz[j]].Y);
			j++;
		}
		//printf("[%d, %d> su paralelni\n", i, j);
		vector < int > pomak;
		for(int k = i;k < j;k++){
		//	printf("pravac %d %d\n", pr[duz[k]], dr[duz[k]]);
			pomak.PB(pos[pr[duz[k]]]);
			pomak.PB(pos[dr[duz[k]]]);
		}
		sort(pomak.begin(), pomak.end());
		int lst = -1;
		for(int k : pomak){
			if(k <= lst) continue;
			int en = k + 1;
			while(en + 1 < n && par(toc[rd[k]], toc[rd[k + 1]], toc[rd[en]], toc[rd[en + 1]]))
				en++;
		//	printf("obrcem %d %d\n", k, en);
			obrni(k, en); lst = en;
		}
		ans = max(ans, T[1].sol);
		i = j;
	}
	printf("%lld\n", ans);
	return 0;
}









Compilation message

bulldozer.cpp: In function 'int main()':
bulldozer.cpp:84:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   84 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
bulldozer.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |   scanf("%d%d%d", &toc[i].X, &toc[i].Y, V + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 512 KB Output is correct
17 Correct 0 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 0 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 640 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 512 KB Output is correct
17 Correct 0 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 0 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 640 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 1751 ms 39552 KB Output is correct
34 Correct 1791 ms 39800 KB Output is correct
35 Correct 1782 ms 39720 KB Output is correct
36 Correct 1716 ms 39716 KB Output is correct
37 Correct 1786 ms 39800 KB Output is correct
38 Correct 1893 ms 39800 KB Output is correct
39 Correct 1865 ms 39728 KB Output is correct
40 Correct 1780 ms 39716 KB Output is correct
41 Correct 1768 ms 39800 KB Output is correct
42 Correct 1823 ms 39800 KB Output is correct
43 Correct 1618 ms 39748 KB Output is correct
44 Correct 1657 ms 39720 KB Output is correct
45 Correct 1573 ms 39716 KB Output is correct
46 Correct 1564 ms 39800 KB Output is correct
47 Correct 1630 ms 39720 KB Output is correct
48 Correct 1624 ms 39680 KB Output is correct
49 Correct 1663 ms 39720 KB Output is correct
50 Correct 1701 ms 39724 KB Output is correct
51 Correct 1699 ms 39800 KB Output is correct
52 Correct 1690 ms 39724 KB Output is correct
53 Correct 1592 ms 39800 KB Output is correct
54 Correct 1616 ms 39800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 4 ms 640 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 0 ms 512 KB Output is correct
17 Correct 0 ms 512 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 0 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 640 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 1751 ms 39552 KB Output is correct
34 Correct 1791 ms 39800 KB Output is correct
35 Correct 1782 ms 39720 KB Output is correct
36 Correct 1716 ms 39716 KB Output is correct
37 Correct 1786 ms 39800 KB Output is correct
38 Correct 1893 ms 39800 KB Output is correct
39 Correct 1865 ms 39728 KB Output is correct
40 Correct 1780 ms 39716 KB Output is correct
41 Correct 1768 ms 39800 KB Output is correct
42 Correct 1823 ms 39800 KB Output is correct
43 Correct 1618 ms 39748 KB Output is correct
44 Correct 1657 ms 39720 KB Output is correct
45 Correct 1573 ms 39716 KB Output is correct
46 Correct 1564 ms 39800 KB Output is correct
47 Correct 1630 ms 39720 KB Output is correct
48 Correct 1624 ms 39680 KB Output is correct
49 Correct 1663 ms 39720 KB Output is correct
50 Correct 1701 ms 39724 KB Output is correct
51 Correct 1699 ms 39800 KB Output is correct
52 Correct 1690 ms 39724 KB Output is correct
53 Correct 1592 ms 39800 KB Output is correct
54 Correct 1616 ms 39800 KB Output is correct
55 Correct 1763 ms 39716 KB Output is correct
56 Correct 1761 ms 39800 KB Output is correct
57 Correct 1780 ms 39720 KB Output is correct
58 Correct 1757 ms 39716 KB Output is correct
59 Correct 1792 ms 39720 KB Output is correct
60 Correct 1751 ms 39800 KB Output is correct
61 Correct 1728 ms 39800 KB Output is correct
62 Correct 1836 ms 39800 KB Output is correct
63 Correct 1795 ms 39800 KB Output is correct
64 Correct 1779 ms 39800 KB Output is correct
65 Correct 1759 ms 39928 KB Output is correct
66 Correct 1775 ms 39928 KB Output is correct
67 Correct 1806 ms 39928 KB Output is correct
68 Correct 1787 ms 39932 KB Output is correct
69 Correct 1770 ms 39928 KB Output is correct
70 Correct 1798 ms 39928 KB Output is correct
71 Correct 1756 ms 39928 KB Output is correct
72 Correct 1781 ms 39928 KB Output is correct
73 Correct 1904 ms 39720 KB Output is correct
74 Correct 1915 ms 39720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 0 ms 512 KB Output is correct
12 Correct 0 ms 512 KB Output is correct
13 Correct 0 ms 512 KB Output is correct
14 Correct 0 ms 512 KB Output is correct
15 Correct 0 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 4 ms 512 KB Output is correct
22 Correct 3 ms 640 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 4 ms 640 KB Output is correct
26 Correct 0 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 0 ms 512 KB Output is correct
29 Correct 0 ms 512 KB Output is correct
30 Correct 0 ms 512 KB Output is correct
31 Correct 0 ms 512 KB Output is correct
32 Correct 0 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 0 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 1751 ms 39552 KB Output is correct
49 Correct 1791 ms 39800 KB Output is correct
50 Correct 1782 ms 39720 KB Output is correct
51 Correct 1716 ms 39716 KB Output is correct
52 Correct 1786 ms 39800 KB Output is correct
53 Correct 1893 ms 39800 KB Output is correct
54 Correct 1865 ms 39728 KB Output is correct
55 Correct 1780 ms 39716 KB Output is correct
56 Correct 1768 ms 39800 KB Output is correct
57 Correct 1823 ms 39800 KB Output is correct
58 Correct 1618 ms 39748 KB Output is correct
59 Correct 1657 ms 39720 KB Output is correct
60 Correct 1573 ms 39716 KB Output is correct
61 Correct 1564 ms 39800 KB Output is correct
62 Correct 1630 ms 39720 KB Output is correct
63 Correct 1624 ms 39680 KB Output is correct
64 Correct 1663 ms 39720 KB Output is correct
65 Correct 1701 ms 39724 KB Output is correct
66 Correct 1699 ms 39800 KB Output is correct
67 Correct 1690 ms 39724 KB Output is correct
68 Correct 1592 ms 39800 KB Output is correct
69 Correct 1616 ms 39800 KB Output is correct
70 Correct 1763 ms 39716 KB Output is correct
71 Correct 1761 ms 39800 KB Output is correct
72 Correct 1780 ms 39720 KB Output is correct
73 Correct 1757 ms 39716 KB Output is correct
74 Correct 1792 ms 39720 KB Output is correct
75 Correct 1751 ms 39800 KB Output is correct
76 Correct 1728 ms 39800 KB Output is correct
77 Correct 1836 ms 39800 KB Output is correct
78 Correct 1795 ms 39800 KB Output is correct
79 Correct 1779 ms 39800 KB Output is correct
80 Correct 1759 ms 39928 KB Output is correct
81 Correct 1775 ms 39928 KB Output is correct
82 Correct 1806 ms 39928 KB Output is correct
83 Correct 1787 ms 39932 KB Output is correct
84 Correct 1770 ms 39928 KB Output is correct
85 Correct 1798 ms 39928 KB Output is correct
86 Correct 1756 ms 39928 KB Output is correct
87 Correct 1781 ms 39928 KB Output is correct
88 Correct 1904 ms 39720 KB Output is correct
89 Correct 1915 ms 39720 KB Output is correct
90 Correct 1836 ms 39612 KB Output is correct
91 Correct 1829 ms 39724 KB Output is correct
92 Correct 1799 ms 39800 KB Output is correct
93 Correct 1743 ms 39800 KB Output is correct
94 Correct 1773 ms 39800 KB Output is correct
95 Correct 1741 ms 39724 KB Output is correct
96 Correct 1793 ms 39752 KB Output is correct
97 Correct 1813 ms 39672 KB Output is correct
98 Correct 1739 ms 39800 KB Output is correct
99 Correct 1767 ms 39680 KB Output is correct
100 Correct 810 ms 48100 KB Output is correct
101 Correct 844 ms 48104 KB Output is correct
102 Correct 826 ms 48100 KB Output is correct
103 Correct 829 ms 48100 KB Output is correct
104 Correct 820 ms 48100 KB Output is correct
105 Correct 1027 ms 48100 KB Output is correct
106 Correct 1008 ms 48100 KB Output is correct
107 Correct 1032 ms 48100 KB Output is correct
108 Correct 1014 ms 48008 KB Output is correct
109 Correct 1033 ms 48004 KB Output is correct
110 Correct 1120 ms 40228 KB Output is correct
111 Correct 1129 ms 40296 KB Output is correct
112 Correct 1171 ms 40320 KB Output is correct
113 Correct 1136 ms 40548 KB Output is correct
114 Correct 1175 ms 40328 KB Output is correct
115 Correct 1143 ms 40376 KB Output is correct
116 Correct 1159 ms 40308 KB Output is correct
117 Correct 1123 ms 40564 KB Output is correct
118 Correct 1187 ms 40436 KB Output is correct
119 Correct 1132 ms 40272 KB Output is correct
120 Correct 1 ms 512 KB Output is correct
121 Correct 0 ms 512 KB Output is correct
122 Correct 1583 ms 39928 KB Output is correct
123 Correct 1611 ms 39972 KB Output is correct
124 Correct 1577 ms 39800 KB Output is correct
125 Correct 1656 ms 39928 KB Output is correct
126 Correct 1582 ms 39928 KB Output is correct
127 Correct 1550 ms 39852 KB Output is correct
128 Correct 1626 ms 39800 KB Output is correct
129 Correct 1581 ms 39968 KB Output is correct
130 Correct 1589 ms 39672 KB Output is correct
131 Correct 1662 ms 39844 KB Output is correct
132 Correct 1618 ms 39804 KB Output is correct
133 Correct 1550 ms 39716 KB Output is correct