Submission #48581

# Submission time Handle Problem Language Result Execution time Memory
48581 2018-05-17T03:13:07 Z Namnamseo Bulldozer (JOI17_bulldozer) C++17
100 / 100
1848 ms 94664 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

#define DBG if(0)

int n;

typedef tuple<int,int,int> Mine;

Mine p[2010];

struct Kumi {
	ll x, y;
	Kumi(ll x_=0, ll y_=0){
		x = x_; y = y_;
		if((x<0 && y==0) || y<0) x=-x, y=-y;
	}
	bool operator<(const Kumi& r) const {
		return x*r.y > y*r.x;
	}
	bool operator==(const Kumi& r) const {
		return x*r.y == y*r.x;
	}
};

void in(){
	read(n);
	//n = 2e3;
	//assert(RAND_MAX == 32767);
	for(int i=1; i<=n; ++i){
		if(1){
			int x, y, z; read(x, y, z);
			p[i] = make_tuple(x, y, z);
		} else {
			for(;;){
				int x=rand();
				int y=rand();
				//int x = (rand() << 15) + rand();
				//int y = (rand() << 15) + rand();
				x = min(x, int(1e9));
				y = min(y, int(1e9));
				bool flg=1;
				for(int j=1; j<i; ++j)
				if(get<0>(p[j]) == x && get<1>(p[j]) == y){
					flg=0;
					break;
				}
				if(flg){
					p[i] = make_tuple(x, y, min(int(1e9), 
					//	(rand()<<15) + rand()
						rand()
					));
					break;
				}
			}
		}
	}
}

Kumi operator-(const Mine& a, const Mine& b){
	return {get<1>(b)-get<1>(a), get<0>(a)-get<0>(b)};
}

pair<Kumi, int> kumis[2001*2000];
int Kn;

void Build(){
	for(int i=1; i<n; ++i){
		for(int j=i+1; j<=n; ++j){
			kumis[Kn++]= make_pair(p[i]-p[j], i);
			kumis[Kn++]= make_pair(p[i]-p[j], j);
		}
	}
	sort(kumis, kumis+Kn);
	Kn = unique(kumis, kumis+Kn) - kumis;
}

int ind[2010];
int rev[2010];

struct CuteSegtree {
	static const int M = 2048;
	ll sum[M<<1];
	ll ls[M<<1];
	ll rs[M<<1];
	ll mg[M<<1];
	int l[M<<1];
	int r[M<<1];
	void init(int L=1, int R=n, int p=1){
		l[p]=L; r[p]=R;
		if(L == R) return;
		int mid=(L+R)/2;
		init(L, mid, p*2);
		init(mid+1, R, p*2+1);
	}
	void put(int pt, ll v){
		int p=1;
		while(true){
			if(l[p] == r[p]) break;
			int mid=(l[p]+r[p])/2;
			p*=2;
			if(mid<pt) ++p;
		}
		sum[p] = v;
		ls[p] = rs[p] = mg[p] = max(0LL, v);
		p/=2;
		while(p){
			sum[p] = sum[p*2] + sum[p*2+1];
			ls[p] = max(ls[p*2], sum[p*2] + ls[p*2+1]);
			rs[p] = max(rs[p*2+1], sum[p*2+1] + rs[p*2]);
			mg[p] = max(rs[p*2] + ls[p*2+1], max(mg[p*2], mg[p*2+1]));
			p/=2;
		}
	}
	/*void put(int pt, ll v, int l=1, int r=n, int p=1){
		if(l == r){
			sum[p] = v;
			ls[p] = rs[p] = mg[p] = max(0LL, v);
			return;
		}
		int mid=(l+r)/2;
		if(pt <= mid) put(pt, v, l, mid, p*2); else put(pt, v, mid+1, r, p*2+1);
		sum[p] = sum[p*2] + sum[p*2+1];
		ls[p] = max(ls[p*2], sum[p*2] + ls[p*2+1]);
		rs[p] = max(rs[p*2+1], sum[p*2+1] + rs[p*2]);
		mg[p] = max(rs[p*2] + ls[p*2+1], max(mg[p*2], mg[p*2+1]));
	}*/
} seg;

int main()
{
	in();
	for(int i=1; i<=n; ++i) ind[i] = i;
	sort(ind+1, ind+n+1, [&](const int& a, const int& b){
		ll ax, ay; tie(ax, ay, ignore) = p[a];
		ll bx, by; tie(bx, by, ignore) = p[b];
		return ax < bx;
	});
	DBG { printf("Initial: "); for(int i=1; i<=n; ++i) printf("%d ", ind[i]); putchar(10); }
	seg.init();
	for(int i=1; i<=n; ++i){
		seg.put(i, get<2>(p[ind[i]]));
		rev[ind[i]]=i;
	}
	ll ans = seg.mg[1];
	Build();
	if(1) for(int i=0; i<Kn;){
		int j=i;
		vector<int> v;
		for(;j<Kn && kumis[i].x == kumis[j].x; ++j) v.pb(kumis[j].y);
		ll ccx = kumis[i].x.x, ccy=kumis[i].x.y;
		DBG { printf("Swap by %lld,%lld : ", ccx, ccy); for(int t:v) printf("%d ", t); putchar(10); }
		sort(all(v), [&](const int& a, const int& b){
			ll va = ccx*get<0>(p[a]) + ccy*get<1>(p[a]);
			ll vb = ccx*get<0>(p[b]) + ccy*get<1>(p[b]);
			if(va != vb) return va<vb;
			va = -ccy*get<0>(p[a]) + ccx*get<1>(p[a]);
			vb = -ccy*get<0>(p[b]) + ccx*get<1>(p[b]);
			return va < vb;
		});
		v.erase(unique(all(v)), v.end());
		//0.9s
		
		vector<int> indices;
		for(int t:v) indices.pb(rev[t]);
		sort(all(indices)); // 0.2s
		
		int m = indices.size();
		for(int i=0; i<m; ++i){
			ind[indices[i]]=v[i];
			rev[v[i]]=indices[i];
			seg.put(indices[i], get<2>(p[v[i]]));
		}
		ans = max(ans, seg.mg[1]);
		DBG { printf("Resulting: "); for(int i=1; i<=n; ++i) printf("%d ", ind[i]); putchar(10); }
		i=j;
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

bulldozer.cpp: In function 'void read(int&)':
bulldozer.cpp:6:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(int& x){ scanf("%d",&x); }
                    ~~~~~^~~~~~~~~
bulldozer.cpp: In function 'void read(ll&)':
bulldozer.cpp:7:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 void read(ll& x){ scanf("%lld",&x); }
                   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 94332 KB Output is correct
2 Correct 69 ms 94328 KB Output is correct
3 Correct 69 ms 94328 KB Output is correct
4 Correct 70 ms 94332 KB Output is correct
5 Correct 70 ms 94328 KB Output is correct
6 Correct 72 ms 94284 KB Output is correct
7 Correct 69 ms 94328 KB Output is correct
8 Correct 70 ms 94328 KB Output is correct
9 Correct 70 ms 94328 KB Output is correct
10 Correct 69 ms 94456 KB Output is correct
11 Correct 69 ms 94328 KB Output is correct
12 Correct 68 ms 94328 KB Output is correct
13 Correct 72 ms 94328 KB Output is correct
14 Correct 69 ms 94344 KB Output is correct
15 Correct 68 ms 94328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 94400 KB Output is correct
2 Correct 72 ms 94328 KB Output is correct
3 Correct 76 ms 94300 KB Output is correct
4 Correct 72 ms 94288 KB Output is correct
5 Correct 76 ms 94408 KB Output is correct
6 Correct 80 ms 94328 KB Output is correct
7 Correct 78 ms 94412 KB Output is correct
8 Correct 77 ms 94328 KB Output is correct
9 Correct 77 ms 94328 KB Output is correct
10 Correct 74 ms 94328 KB Output is correct
11 Correct 74 ms 94328 KB Output is correct
12 Correct 74 ms 94328 KB Output is correct
13 Correct 69 ms 94252 KB Output is correct
14 Correct 70 ms 94328 KB Output is correct
15 Correct 69 ms 94328 KB Output is correct
16 Correct 68 ms 94328 KB Output is correct
17 Correct 70 ms 94356 KB Output is correct
18 Correct 67 ms 94328 KB Output is correct
19 Correct 69 ms 94328 KB Output is correct
20 Correct 67 ms 94328 KB Output is correct
21 Correct 72 ms 94456 KB Output is correct
22 Correct 75 ms 94328 KB Output is correct
23 Correct 71 ms 94328 KB Output is correct
24 Correct 75 ms 94328 KB Output is correct
25 Correct 74 ms 94300 KB Output is correct
26 Correct 76 ms 94320 KB Output is correct
27 Correct 75 ms 94328 KB Output is correct
28 Correct 75 ms 94328 KB Output is correct
29 Correct 76 ms 94396 KB Output is correct
30 Correct 75 ms 94328 KB Output is correct
31 Correct 71 ms 94328 KB Output is correct
32 Correct 76 ms 94328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 94400 KB Output is correct
2 Correct 72 ms 94328 KB Output is correct
3 Correct 76 ms 94300 KB Output is correct
4 Correct 72 ms 94288 KB Output is correct
5 Correct 76 ms 94408 KB Output is correct
6 Correct 80 ms 94328 KB Output is correct
7 Correct 78 ms 94412 KB Output is correct
8 Correct 77 ms 94328 KB Output is correct
9 Correct 77 ms 94328 KB Output is correct
10 Correct 74 ms 94328 KB Output is correct
11 Correct 74 ms 94328 KB Output is correct
12 Correct 74 ms 94328 KB Output is correct
13 Correct 69 ms 94252 KB Output is correct
14 Correct 70 ms 94328 KB Output is correct
15 Correct 69 ms 94328 KB Output is correct
16 Correct 68 ms 94328 KB Output is correct
17 Correct 70 ms 94356 KB Output is correct
18 Correct 67 ms 94328 KB Output is correct
19 Correct 69 ms 94328 KB Output is correct
20 Correct 67 ms 94328 KB Output is correct
21 Correct 72 ms 94456 KB Output is correct
22 Correct 75 ms 94328 KB Output is correct
23 Correct 71 ms 94328 KB Output is correct
24 Correct 75 ms 94328 KB Output is correct
25 Correct 74 ms 94300 KB Output is correct
26 Correct 76 ms 94320 KB Output is correct
27 Correct 75 ms 94328 KB Output is correct
28 Correct 75 ms 94328 KB Output is correct
29 Correct 76 ms 94396 KB Output is correct
30 Correct 75 ms 94328 KB Output is correct
31 Correct 71 ms 94328 KB Output is correct
32 Correct 76 ms 94328 KB Output is correct
33 Correct 1735 ms 94532 KB Output is correct
34 Correct 1734 ms 94540 KB Output is correct
35 Correct 1711 ms 94532 KB Output is correct
36 Correct 1689 ms 94536 KB Output is correct
37 Correct 1691 ms 94532 KB Output is correct
38 Correct 1682 ms 94556 KB Output is correct
39 Correct 1666 ms 94548 KB Output is correct
40 Correct 1664 ms 94544 KB Output is correct
41 Correct 1659 ms 94532 KB Output is correct
42 Correct 1692 ms 94536 KB Output is correct
43 Correct 1648 ms 94540 KB Output is correct
44 Correct 1678 ms 94540 KB Output is correct
45 Correct 1680 ms 94536 KB Output is correct
46 Correct 1688 ms 94532 KB Output is correct
47 Correct 1670 ms 94536 KB Output is correct
48 Correct 1649 ms 94540 KB Output is correct
49 Correct 1651 ms 94532 KB Output is correct
50 Correct 1666 ms 94532 KB Output is correct
51 Correct 1706 ms 94584 KB Output is correct
52 Correct 1707 ms 94564 KB Output is correct
53 Correct 1724 ms 94532 KB Output is correct
54 Correct 1669 ms 94536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 94400 KB Output is correct
2 Correct 72 ms 94328 KB Output is correct
3 Correct 76 ms 94300 KB Output is correct
4 Correct 72 ms 94288 KB Output is correct
5 Correct 76 ms 94408 KB Output is correct
6 Correct 80 ms 94328 KB Output is correct
7 Correct 78 ms 94412 KB Output is correct
8 Correct 77 ms 94328 KB Output is correct
9 Correct 77 ms 94328 KB Output is correct
10 Correct 74 ms 94328 KB Output is correct
11 Correct 74 ms 94328 KB Output is correct
12 Correct 74 ms 94328 KB Output is correct
13 Correct 69 ms 94252 KB Output is correct
14 Correct 70 ms 94328 KB Output is correct
15 Correct 69 ms 94328 KB Output is correct
16 Correct 68 ms 94328 KB Output is correct
17 Correct 70 ms 94356 KB Output is correct
18 Correct 67 ms 94328 KB Output is correct
19 Correct 69 ms 94328 KB Output is correct
20 Correct 67 ms 94328 KB Output is correct
21 Correct 72 ms 94456 KB Output is correct
22 Correct 75 ms 94328 KB Output is correct
23 Correct 71 ms 94328 KB Output is correct
24 Correct 75 ms 94328 KB Output is correct
25 Correct 74 ms 94300 KB Output is correct
26 Correct 76 ms 94320 KB Output is correct
27 Correct 75 ms 94328 KB Output is correct
28 Correct 75 ms 94328 KB Output is correct
29 Correct 76 ms 94396 KB Output is correct
30 Correct 75 ms 94328 KB Output is correct
31 Correct 71 ms 94328 KB Output is correct
32 Correct 76 ms 94328 KB Output is correct
33 Correct 1735 ms 94532 KB Output is correct
34 Correct 1734 ms 94540 KB Output is correct
35 Correct 1711 ms 94532 KB Output is correct
36 Correct 1689 ms 94536 KB Output is correct
37 Correct 1691 ms 94532 KB Output is correct
38 Correct 1682 ms 94556 KB Output is correct
39 Correct 1666 ms 94548 KB Output is correct
40 Correct 1664 ms 94544 KB Output is correct
41 Correct 1659 ms 94532 KB Output is correct
42 Correct 1692 ms 94536 KB Output is correct
43 Correct 1648 ms 94540 KB Output is correct
44 Correct 1678 ms 94540 KB Output is correct
45 Correct 1680 ms 94536 KB Output is correct
46 Correct 1688 ms 94532 KB Output is correct
47 Correct 1670 ms 94536 KB Output is correct
48 Correct 1649 ms 94540 KB Output is correct
49 Correct 1651 ms 94532 KB Output is correct
50 Correct 1666 ms 94532 KB Output is correct
51 Correct 1706 ms 94584 KB Output is correct
52 Correct 1707 ms 94564 KB Output is correct
53 Correct 1724 ms 94532 KB Output is correct
54 Correct 1669 ms 94536 KB Output is correct
55 Correct 1678 ms 94544 KB Output is correct
56 Correct 1721 ms 94532 KB Output is correct
57 Correct 1685 ms 94540 KB Output is correct
58 Correct 1733 ms 94540 KB Output is correct
59 Correct 1704 ms 94536 KB Output is correct
60 Correct 1694 ms 94536 KB Output is correct
61 Correct 1684 ms 94536 KB Output is correct
62 Correct 1686 ms 94548 KB Output is correct
63 Correct 1721 ms 94544 KB Output is correct
64 Correct 1713 ms 94536 KB Output is correct
65 Correct 1771 ms 94556 KB Output is correct
66 Correct 1714 ms 94556 KB Output is correct
67 Correct 1709 ms 94560 KB Output is correct
68 Correct 1736 ms 94572 KB Output is correct
69 Correct 1774 ms 94560 KB Output is correct
70 Correct 1746 ms 94560 KB Output is correct
71 Correct 1697 ms 94564 KB Output is correct
72 Correct 1701 ms 94560 KB Output is correct
73 Correct 1684 ms 94584 KB Output is correct
74 Correct 1685 ms 94560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 94332 KB Output is correct
2 Correct 69 ms 94328 KB Output is correct
3 Correct 69 ms 94328 KB Output is correct
4 Correct 70 ms 94332 KB Output is correct
5 Correct 70 ms 94328 KB Output is correct
6 Correct 72 ms 94284 KB Output is correct
7 Correct 69 ms 94328 KB Output is correct
8 Correct 70 ms 94328 KB Output is correct
9 Correct 70 ms 94328 KB Output is correct
10 Correct 69 ms 94456 KB Output is correct
11 Correct 69 ms 94328 KB Output is correct
12 Correct 68 ms 94328 KB Output is correct
13 Correct 72 ms 94328 KB Output is correct
14 Correct 69 ms 94344 KB Output is correct
15 Correct 68 ms 94328 KB Output is correct
16 Correct 74 ms 94400 KB Output is correct
17 Correct 72 ms 94328 KB Output is correct
18 Correct 76 ms 94300 KB Output is correct
19 Correct 72 ms 94288 KB Output is correct
20 Correct 76 ms 94408 KB Output is correct
21 Correct 80 ms 94328 KB Output is correct
22 Correct 78 ms 94412 KB Output is correct
23 Correct 77 ms 94328 KB Output is correct
24 Correct 77 ms 94328 KB Output is correct
25 Correct 74 ms 94328 KB Output is correct
26 Correct 74 ms 94328 KB Output is correct
27 Correct 74 ms 94328 KB Output is correct
28 Correct 69 ms 94252 KB Output is correct
29 Correct 70 ms 94328 KB Output is correct
30 Correct 69 ms 94328 KB Output is correct
31 Correct 68 ms 94328 KB Output is correct
32 Correct 70 ms 94356 KB Output is correct
33 Correct 67 ms 94328 KB Output is correct
34 Correct 69 ms 94328 KB Output is correct
35 Correct 67 ms 94328 KB Output is correct
36 Correct 72 ms 94456 KB Output is correct
37 Correct 75 ms 94328 KB Output is correct
38 Correct 71 ms 94328 KB Output is correct
39 Correct 75 ms 94328 KB Output is correct
40 Correct 74 ms 94300 KB Output is correct
41 Correct 76 ms 94320 KB Output is correct
42 Correct 75 ms 94328 KB Output is correct
43 Correct 75 ms 94328 KB Output is correct
44 Correct 76 ms 94396 KB Output is correct
45 Correct 75 ms 94328 KB Output is correct
46 Correct 71 ms 94328 KB Output is correct
47 Correct 76 ms 94328 KB Output is correct
48 Correct 1735 ms 94532 KB Output is correct
49 Correct 1734 ms 94540 KB Output is correct
50 Correct 1711 ms 94532 KB Output is correct
51 Correct 1689 ms 94536 KB Output is correct
52 Correct 1691 ms 94532 KB Output is correct
53 Correct 1682 ms 94556 KB Output is correct
54 Correct 1666 ms 94548 KB Output is correct
55 Correct 1664 ms 94544 KB Output is correct
56 Correct 1659 ms 94532 KB Output is correct
57 Correct 1692 ms 94536 KB Output is correct
58 Correct 1648 ms 94540 KB Output is correct
59 Correct 1678 ms 94540 KB Output is correct
60 Correct 1680 ms 94536 KB Output is correct
61 Correct 1688 ms 94532 KB Output is correct
62 Correct 1670 ms 94536 KB Output is correct
63 Correct 1649 ms 94540 KB Output is correct
64 Correct 1651 ms 94532 KB Output is correct
65 Correct 1666 ms 94532 KB Output is correct
66 Correct 1706 ms 94584 KB Output is correct
67 Correct 1707 ms 94564 KB Output is correct
68 Correct 1724 ms 94532 KB Output is correct
69 Correct 1669 ms 94536 KB Output is correct
70 Correct 1678 ms 94544 KB Output is correct
71 Correct 1721 ms 94532 KB Output is correct
72 Correct 1685 ms 94540 KB Output is correct
73 Correct 1733 ms 94540 KB Output is correct
74 Correct 1704 ms 94536 KB Output is correct
75 Correct 1694 ms 94536 KB Output is correct
76 Correct 1684 ms 94536 KB Output is correct
77 Correct 1686 ms 94548 KB Output is correct
78 Correct 1721 ms 94544 KB Output is correct
79 Correct 1713 ms 94536 KB Output is correct
80 Correct 1771 ms 94556 KB Output is correct
81 Correct 1714 ms 94556 KB Output is correct
82 Correct 1709 ms 94560 KB Output is correct
83 Correct 1736 ms 94572 KB Output is correct
84 Correct 1774 ms 94560 KB Output is correct
85 Correct 1746 ms 94560 KB Output is correct
86 Correct 1697 ms 94564 KB Output is correct
87 Correct 1701 ms 94560 KB Output is correct
88 Correct 1684 ms 94584 KB Output is correct
89 Correct 1685 ms 94560 KB Output is correct
90 Correct 1724 ms 94532 KB Output is correct
91 Correct 1686 ms 94540 KB Output is correct
92 Correct 1701 ms 94532 KB Output is correct
93 Correct 1667 ms 94540 KB Output is correct
94 Correct 1676 ms 94532 KB Output is correct
95 Correct 1698 ms 94532 KB Output is correct
96 Correct 1721 ms 94536 KB Output is correct
97 Correct 1735 ms 94540 KB Output is correct
98 Correct 1764 ms 94548 KB Output is correct
99 Correct 1779 ms 94552 KB Output is correct
100 Correct 1042 ms 94560 KB Output is correct
101 Correct 1051 ms 94564 KB Output is correct
102 Correct 1058 ms 94568 KB Output is correct
103 Correct 1047 ms 94560 KB Output is correct
104 Correct 1060 ms 94556 KB Output is correct
105 Correct 1258 ms 94556 KB Output is correct
106 Correct 1250 ms 94536 KB Output is correct
107 Correct 1331 ms 94560 KB Output is correct
108 Correct 1270 ms 94556 KB Output is correct
109 Correct 1248 ms 94536 KB Output is correct
110 Correct 1330 ms 94572 KB Output is correct
111 Correct 1263 ms 94568 KB Output is correct
112 Correct 1282 ms 94532 KB Output is correct
113 Correct 1272 ms 94664 KB Output is correct
114 Correct 1272 ms 94560 KB Output is correct
115 Correct 1279 ms 94564 KB Output is correct
116 Correct 1238 ms 94560 KB Output is correct
117 Correct 1264 ms 94580 KB Output is correct
118 Correct 1254 ms 94560 KB Output is correct
119 Correct 1242 ms 94560 KB Output is correct
120 Correct 70 ms 94368 KB Output is correct
121 Correct 71 ms 94296 KB Output is correct
122 Correct 1690 ms 94556 KB Output is correct
123 Correct 1694 ms 94584 KB Output is correct
124 Correct 1705 ms 94544 KB Output is correct
125 Correct 1695 ms 94584 KB Output is correct
126 Correct 1681 ms 94552 KB Output is correct
127 Correct 1699 ms 94544 KB Output is correct
128 Correct 1699 ms 94548 KB Output is correct
129 Correct 1681 ms 94560 KB Output is correct
130 Correct 1739 ms 94548 KB Output is correct
131 Correct 1710 ms 94540 KB Output is correct
132 Correct 1848 ms 94548 KB Output is correct
133 Correct 1703 ms 94544 KB Output is correct