Submission #26653

# Submission time Handle Problem Language Result Execution time Memory
26653 2017-07-04T05:28:36 Z kajebiii Bulldozer (JOI17_bulldozer) C++14
0 / 100
3 ms 640 KB
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 2e3 + 100;

int sign(ll x) {return (x>0) - (x<0); }
struct PT {
	int x, y, c;
	PT() {}
	PT(int xx, int yy, int cc) : x(xx), y(yy), c(cc) {}
	PT operator-(const PT &o) const {return PT(x-o.x, y-o.y, 0); }
	ll cross(const PT &o) const{return 1ll * x * o.y - 1ll * y * o.x;}
	ll dot(const PT &o) const {return 1ll * x * o.x + 1ll * y * o.y;}
	int ccw(const PT &o) const {return sign(cross(o));}
	bool operator<(const PT &o) const {
		if(y != o.y) return y < o.y;
		return x < o.x;
	}
};
vector<PT> Ps;

struct LN {
	PT sl; int p;
	int i, j;
	LN(int ii, int jj) : i(ii), j(jj) {
		sl = Ps[j] - Ps[i];
		if(sl.y > 0 || sl.y == 0 && sl.x > 0) p = 0;
		else p = 1;
	}
	bool operator<(const LN &o) const {
		if(p != o.p) return p < o.p;
		if(sl.ccw(o.sl) != 0) return sl.ccw(o.sl) > 0;
		if(sl.dot(Ps[i]) != sl.dot(Ps[o.i])) return sl.dot(Ps[i]) < sl.dot(Ps[o.i]);
		return sl.dot(Ps[j]) < sl.dot(Ps[o.j]);
	}
};
vector<LN> Ls;

struct IDX {
	int P; vector<ll> l, r, s, m;
	IDX() {}
	IDX(int n) {
		for(P=1; P<n; P<<=1);
		l = r = s = m = vector<ll>(2*P, 0);
	}
	void update(int v, int k) {
		v += P;
		if(k >= 0) l[v] = r[v] = m[v] = s[v] = k;
		else l[v] = r[v] = m[v] = 0, s[v] = k;
		while(v >>= 1) {
			l[v] = max(l[v*2], s[v*2] + l[v*2+1]);
			r[v] = max(r[v*2+1], s[v*2+1] + r[v*2]);
			s[v] = s[v*2] + s[v*2+1];
			m[v] = max(r[v*2] + l[v*2+1], max(m[v*2], m[v*2+1]));
		}
	}
};

int N, Ix[MAX_N];
int main() {
	cin >> N;
	REP(i, N) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		Ps.push_back(PT(x, y, c));
	}
	sort(ALL(Ps));
	REP(i, N) REP(j, N) if(i < j) Ls.push_back(LN(i, j));
	sort(ALL(Ls));
	REP(i, N) Ix[i] = i;

	IDX idx = IDX(N);
	REP(i, N) idx.update(i, Ps[i].c);
	ll ans = idx.m[1];
	for(int i=0, j=0; i<N; i=j) {
//		for(int k=0; k<N; k++) printf("[%d %d %d] ", Ps[k].x, Ps[k].y, Ps[k].c); puts("");
		while(j < N && Ls[i].sl.ccw(Ls[j].sl) == 0) {
			int &x = Ix[Ls[j].i], &y = Ix[Ls[j].j];
			swap(Ps[x], Ps[y]);
			swap(x, y);
			idx.update(x, Ps[x].c);
			idx.update(y, Ps[y].c);
			j++;
//			printf("swap %d %d\n", x, y);
		}
		ans = max(ans, idx.m[1]);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

bulldozer.cpp: In constructor 'LN::LN(int, int)':
bulldozer.cpp:40:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   if(sl.y > 0 || sl.y == 0 && sl.x > 0) p = 0;
                  ~~~~~~~~~~^~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:76:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, c; scanf("%d%d%d", &x, &y, &c);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 2 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 3 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 640 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 2 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 3 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -