답안 #129766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129766 2019-07-13T07:38:47 Z 윤교준(#3140) 도장 모으기 (JOI14_stamps) C++14
85 / 100
1000 ms 72352 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
lll operator * (const pll &a, const pll &b) { return lll(a.first)*b.second - lll(b.first)*a.second; }
lll ccw(const pll &a, const pll &b, const pll &c) { return a*b + b*c + c*a; }

const int MAXN = 3055;

struct CHT {
	pll P[MAXN];
	int n;

	void init() { n = 0; }
	void push(const pll &p) {
		for(; 1 < n && ccw(P[n-2], P[n-1], p) <= 0; n--);
		P[n++] = p;
	}
	ll f(int i, ll X) { return P[i].first*X + P[i].second; }
	ll get(ll X) {
		ll ret = INFLL;
		for(int i = 0; i < n; i++)
			upmin(ret, f(i, X));
		return ret;
		int s = 0, e = n-1; for(int m; s <= e;) {
			m = (s+e) >> 1;
			ll tl = f(m, X), tr = f(m+1, X);
			if(tr < tl) {
				if(tr < ret) ret = tr;
				s = m+1;
			} else {
				if(tl < ret) ret = tl;
				e = m-1;
			}
		}
		return ret;
	}
} cht;

ll dp[MAXN][MAXN];

int A[MAXN], B[MAXN], C[MAXN], D[MAXN];

int N, T;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> T;
	for(int i = 1; i <= N; i++)
		cin >> A[i] >> B[i] >> C[i] >> D[i];
	
	fill(dp[0], dp[N+2]+(N+2), INFLL);
	dp[0][0] = 0;

	for(int i = 1; i <= N; i++) {
		cht.init();
		for(int j = 0, t; j <= N; j++) {
			t = j-1;
			if(0 <= t) cht.push({t, dp[i-1][t] + ll(2*t+1)*T});
			upmin(dp[i][j], cht.get(-B[i]-C[i]) + ll(B[i]+C[i])*j);
		}
		if(1 < i) {
		cht.init();
		for(int j = N, t; 0 <= j; j--) {
			t = j+1;
			if(t <= N) cht.push({-t, dp[i-1][t] + ll(2*t+1)*T});
			upmin(dp[i][j], cht.get(-A[i]-D[i]) - ll(A[i]+D[i])*j);
		}
		}
		for(int j = 0; j <= N; j++) {
			ll &ret = dp[i][j];
			upmin(ret, dp[i-1][j] + A[i] + B[i] + ll(j*2+1)*T);
			if(1 < i && j) upmin(ret, dp[i-1][j] + C[i] + D[i] + ll(j*2+1)*T);
		}
	}
	
	cout << dp[N][0] + T << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 888 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 2 ms 760 KB Output is correct
8 Correct 2 ms 760 KB Output is correct
9 Correct 2 ms 760 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 2 ms 760 KB Output is correct
13 Correct 2 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 5 ms 2808 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1756 KB Output is correct
7 Correct 4 ms 2552 KB Output is correct
8 Correct 4 ms 2808 KB Output is correct
9 Correct 4 ms 2808 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 5 ms 2808 KB Output is correct
12 Correct 4 ms 2808 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 5 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 465 ms 72084 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 492 ms 72312 KB Output is correct
4 Correct 373 ms 63836 KB Output is correct
5 Correct 296 ms 56148 KB Output is correct
6 Correct 390 ms 36692 KB Output is correct
7 Correct 106 ms 27980 KB Output is correct
8 Correct 470 ms 72352 KB Output is correct
9 Execution timed out 1084 ms 72184 KB Time limit exceeded
10 Halted 0 ms 0 KB -