답안 #143510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143510 2019-08-14T12:24:56 Z kig9981 버스 (JOI14_bus) C++17
100 / 100
514 ms 35832 KB
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<tuple<int,int,int>> adj[100000];
vector<int> D[100000], x[100000];

int solve(int c, int t)
{
	if(c==0) return x[c][t];
	if(D[c][t]!=0x7fffffff) return D[c][t];
	if(t) D[c][t]=solve(c,t-1);
	else D[c][t]=-1;
	for(int i=lower_bound(adj[c].begin(),adj[c].end(),make_tuple(x[c][t],-1,-1))-adj[c].begin();i<adj[c].size() && get<0>(adj[c][i])==x[c][t];i++) {
		int tmp, n, v;
		tie(tmp,n,v)=adj[c][i];
		v=lower_bound(x[n].begin(),x[n].end(),v)-x[n].begin();
		D[c][t]=max(D[c][t],solve(n,v));
	}
	return D[c][t];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N, M;
	for(cin>>N>>M;M--;) {
		int A, B, X, Y;
		cin>>A>>B>>X>>Y;
		adj[--B].emplace_back(Y,--A,X);
		x[A].push_back(X);
		x[B].push_back(Y);
	}
	for(int i=0;i<N;i++) {
		sort(adj[i].begin(),adj[i].end());
		sort(x[i].begin(),x[i].end());
		x[i].resize(unique(x[i].begin(),x[i].end())-x[i].begin());
		D[i].resize(x[i].size(),0x7fffffff);
	}
	for(int i=0;i<x[N-1].size();i++) solve(N-1,i);
	for(cin>>M;M--;) {
		int L;
		cin>>L;
		L=upper_bound(x[N-1].begin(),x[N-1].end(),L)-x[N-1].begin()-1;
		if(L==-1 || D[N-1][L]==-1) cout<<"-1\n";
		else cout<<D[N-1][L]<<'\n';
	}
	return 0;
}

Compilation message

bus.cpp: In function 'int solve(int, int)':
bus.cpp:22:95: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=lower_bound(adj[c].begin(),adj[c].end(),make_tuple(x[c][t],-1,-1))-adj[c].begin();i<adj[c].size() && get<0>(adj[c][i])==x[c][t];i++) {
                                                                                              ~^~~~~~~~~~~~~~
bus.cpp: In function 'int main()':
bus.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<x[N-1].size();i++) solve(N-1,i);
              ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7544 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7420 KB Output is correct
5 Correct 10 ms 7416 KB Output is correct
6 Correct 9 ms 7416 KB Output is correct
7 Correct 9 ms 7416 KB Output is correct
8 Correct 9 ms 7416 KB Output is correct
9 Correct 9 ms 7548 KB Output is correct
10 Correct 11 ms 7544 KB Output is correct
11 Correct 10 ms 7544 KB Output is correct
12 Correct 10 ms 7544 KB Output is correct
13 Correct 11 ms 7948 KB Output is correct
14 Correct 10 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7544 KB Output is correct
2 Correct 36 ms 9112 KB Output is correct
3 Correct 35 ms 9104 KB Output is correct
4 Correct 11 ms 7644 KB Output is correct
5 Correct 12 ms 7544 KB Output is correct
6 Correct 11 ms 7544 KB Output is correct
7 Correct 26 ms 7928 KB Output is correct
8 Correct 9 ms 7416 KB Output is correct
9 Correct 25 ms 8184 KB Output is correct
10 Correct 38 ms 9208 KB Output is correct
11 Correct 27 ms 8572 KB Output is correct
12 Correct 41 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 398 ms 30584 KB Output is correct
2 Correct 435 ms 30532 KB Output is correct
3 Correct 401 ms 30428 KB Output is correct
4 Correct 395 ms 30652 KB Output is correct
5 Correct 415 ms 30532 KB Output is correct
6 Correct 427 ms 30464 KB Output is correct
7 Correct 284 ms 26796 KB Output is correct
8 Correct 410 ms 30252 KB Output is correct
9 Correct 437 ms 30440 KB Output is correct
10 Correct 306 ms 27512 KB Output is correct
11 Correct 286 ms 27384 KB Output is correct
12 Correct 281 ms 27512 KB Output is correct
13 Correct 280 ms 27340 KB Output is correct
14 Correct 284 ms 27384 KB Output is correct
15 Correct 287 ms 27512 KB Output is correct
16 Correct 195 ms 34808 KB Output is correct
17 Correct 198 ms 34904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 32120 KB Output is correct
2 Correct 433 ms 31672 KB Output is correct
3 Correct 433 ms 32248 KB Output is correct
4 Correct 428 ms 32124 KB Output is correct
5 Correct 436 ms 31844 KB Output is correct
6 Correct 424 ms 31988 KB Output is correct
7 Correct 311 ms 28464 KB Output is correct
8 Correct 422 ms 31992 KB Output is correct
9 Correct 448 ms 32156 KB Output is correct
10 Correct 319 ms 29048 KB Output is correct
11 Correct 338 ms 28952 KB Output is correct
12 Correct 317 ms 28792 KB Output is correct
13 Correct 318 ms 28920 KB Output is correct
14 Correct 316 ms 29048 KB Output is correct
15 Correct 315 ms 29048 KB Output is correct
16 Correct 212 ms 35832 KB Output is correct