Submission #17666

# Submission time Handle Problem Language Result Execution time Memory
17666 2016-01-10T11:56:53 Z chatterboy 막대기 (KOI13_game) C++14
0 / 100
111 ms 3936 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define MAXN 100001
typedef long long ll;
struct Stick {
	int t, d;
};
int N, L;
Stick A[MAXN];
map<int,vector<int>> B, C; // t, d
ll cache[MAXN];
ll solve(int p) {
	ll &ret = cache[p];
	if (ret != -1) return ret;
	ret = 0;
	vector<int> vB = B[A[p].t];
	vector<int> vC = C[A[p].d];
	for (int i=0; i<vB.size(); ++i)
		if (p!=vB[i] && A[vB[i]].d>A[p].d)
			ret = max(ret, solve(vB[i]));
	for (int i=0; i<vC.size(); ++i)
		if (p!=vC[i] && A[vC[i]].t>A[p].t)
			ret = max(ret, solve(vC[i]));
	return ret=ret+L+abs(A[p].t-A[p].d);
}
int main() {
	memset(cache,-1,sizeof cache);
	scanf("%d%d", &N, &L);
	for (int i=1; i<=N; ++i) {
		scanf("%d%d", &A[i].t, &A[i].d);
		B[A[i].t].push_back(i);
		C[A[i].d].push_back(i);
	}
	ll sol = 0;
	for (int i=1; i<=N; ++i)
		sol = max(sol, solve(i));
	printf("%lld", sol);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3144 KB Output is correct
2 Incorrect 0 ms 3144 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 3936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3144 KB Output is correct
2 Incorrect 0 ms 3144 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 3804 KB Output isn't correct
2 Halted 0 ms 0 KB -