Submission #25561

# Submission time Handle Problem Language Result Execution time Memory
25561 2017-06-23T05:05:57 Z zigui 버스 (JOI14_bus) C++14
0 / 100
449 ms 14652 KB
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MX = 100005;

struct bus{
	bus(int dst, int p, int q):dst(dst), p(p), q(q){}
	int dst, p, q;
};

vector<bus> G[MX];
vector<pii> T[MX];
int N, M;
int a, b, c, d;

pii get_time(bus c){
	int d = c.dst;
	if( d == N ) return pii(c.p, c.q);
	else{
		auto it = lower_bound(T[d].begin(), T[d].end(), pii(c.q, -1e9));
		if( it == T[d].end() ) return pii(c.p, 1e9);
		else return pii(c.p, it->second);
	}
}

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= M; i++){
		scanf("%d%d%d%d", &a, &b, &c, &d);
		G[a].emplace_back(b, c, d);
	}

	for(int i = N-1; i >= 1; i--){
		vector<pii> L;
		for(bus c : G[i]){
			L.push_back(get_time(c));
		}
		sort(L.begin(), L.end());
		for(pii c : L){
			while(T[i].size() && T[i].back().second >= c.second ) T[i].pop_back();
			T[i].push_back(c);
		}
	}
	vector<pii> X;
	for(pii c : T[1]) X.emplace_back(c.second, c.first);
	int Q;
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++){
		scanf("%d", &a);
		auto it = upper_bound(X.begin(), X.end(), pii(a, 1e9));
		if( it == X.begin() ) printf("-1\n");
		else printf("%d\n", (--it)->second);
	}
}

Compilation message

bus.cpp: In function 'int main()':
bus.cpp:36:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
                       ^
bus.cpp:38:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &a, &b, &c, &d);
                                    ^
bus.cpp:56:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
                 ^
bus.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5864 KB Output is correct
2 Correct 3 ms 5864 KB Output is correct
3 Correct 0 ms 5864 KB Output is correct
4 Correct 0 ms 5864 KB Output is correct
5 Correct 3 ms 5864 KB Output is correct
6 Correct 3 ms 5864 KB Output is correct
7 Correct 3 ms 5864 KB Output is correct
8 Correct 3 ms 5864 KB Output is correct
9 Incorrect 3 ms 5864 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5864 KB Output is correct
2 Correct 46 ms 5864 KB Output is correct
3 Correct 29 ms 5864 KB Output is correct
4 Correct 6 ms 5864 KB Output is correct
5 Correct 3 ms 5864 KB Output is correct
6 Incorrect 0 ms 5864 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 373 ms 14576 KB Output is correct
2 Correct 399 ms 14576 KB Output is correct
3 Correct 409 ms 14576 KB Output is correct
4 Correct 293 ms 14576 KB Output is correct
5 Correct 286 ms 14572 KB Output is correct
6 Correct 326 ms 14612 KB Output is correct
7 Correct 246 ms 11840 KB Output is correct
8 Correct 349 ms 14652 KB Output is correct
9 Correct 309 ms 14612 KB Output is correct
10 Correct 243 ms 12340 KB Output is correct
11 Incorrect 243 ms 12476 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 389 ms 14576 KB Output is correct
2 Correct 413 ms 14576 KB Output is correct
3 Correct 429 ms 14576 KB Output is correct
4 Correct 383 ms 14576 KB Output is correct
5 Correct 449 ms 14572 KB Output is correct
6 Correct 443 ms 14612 KB Output is correct
7 Incorrect 279 ms 11840 KB Output isn't correct
8 Halted 0 ms 0 KB -