Submission #199349

# Submission time Handle Problem Language Result Execution time Memory
199349 2020-01-31T15:47:50 Z arnold518 버스 (JOI14_bus) C++14
85 / 100
260 ms 21496 KB
#include <bits/stdc++.h>
using namespace std;

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

const int MAXN = 3e5;
const int MAXM = 3e5;

struct Data
{
	int A, B, X, Y;
};

int N, M, Q;
Data E[MAXM+10];
vector<pii> A[MAXN+10];

int main()
{
	int i, j;

	scanf("%d%d", &N, &M);
	for(i=1; i<=M; i++) scanf("%d%d%d%d", &E[i].A, &E[i].B, &E[i].X, &E[i].Y);
	sort(E+1, E+M+1, [&](const Data &p, const Data &q) { return p.X>q.X; });

	for(i=1; i<=M; i++)
	{
		if(E[i].A==N) continue;
		int v;
		if(E[i].B==N) v=E[i].Y;
		else
		{
			auto it=upper_bound(A[E[i].B].begin(), A[E[i].B].end(), pii(E[i].Y, -1), greater<pii>());
			if(it==A[E[i].B].begin()) v=987654321;
			else v=(it-1)->second;
		}
		if(v!=987654321 && (A[E[i].A].empty() || A[E[i].A].back().second>v)) A[E[i].A].push_back({E[i].X, v});
	}

	map<int, int> M;
	for(auto it : A[1]) M[it.second]=it.first;
	
	scanf("%d", &Q);
	while(Q--)
	{
		int x;
		scanf("%d", &x);
		auto it=M.upper_bound(x);
		if(it==M.begin()) printf("-1\n");
		else printf("%d\n", (--it)->second);
	}
}

Compilation message

bus.cpp: In function 'int main()':
bus.cpp:22:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
bus.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
bus.cpp:25:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=M; i++) scanf("%d%d%d%d", &E[i].A, &E[i].B, &E[i].X, &E[i].Y);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bus.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
bus.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 10 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 10 ms 7416 KB Output is correct
6 Correct 10 ms 7416 KB Output is correct
7 Correct 10 ms 7416 KB Output is correct
8 Correct 10 ms 7416 KB Output is correct
9 Correct 9 ms 7416 KB Output is correct
10 Correct 10 ms 7416 KB Output is correct
11 Correct 12 ms 7416 KB Output is correct
12 Correct 11 ms 7416 KB Output is correct
13 Correct 12 ms 7420 KB Output is correct
14 Correct 11 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 45 ms 8184 KB Output is correct
3 Correct 44 ms 8056 KB Output is correct
4 Correct 14 ms 7416 KB Output is correct
5 Correct 13 ms 7416 KB Output is correct
6 Correct 12 ms 7416 KB Output is correct
7 Correct 30 ms 7672 KB Output is correct
8 Correct 10 ms 7416 KB Output is correct
9 Correct 32 ms 7672 KB Output is correct
10 Correct 44 ms 8056 KB Output is correct
11 Correct 35 ms 7672 KB Output is correct
12 Correct 56 ms 8440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 12152 KB Output is correct
2 Correct 230 ms 12024 KB Output is correct
3 Correct 230 ms 12284 KB Output is correct
4 Correct 229 ms 12152 KB Output is correct
5 Correct 231 ms 12024 KB Output is correct
6 Correct 230 ms 12152 KB Output is correct
7 Correct 224 ms 12536 KB Output is correct
8 Correct 244 ms 13048 KB Output is correct
9 Correct 246 ms 12128 KB Output is correct
10 Correct 212 ms 12280 KB Output is correct
11 Correct 213 ms 12156 KB Output is correct
12 Execution timed out 52 ms 9720 KB Time limit exceeded (wall clock)
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 253 ms 12664 KB Output is correct
2 Correct 248 ms 12408 KB Output is correct
3 Correct 255 ms 12792 KB Output is correct
4 Correct 253 ms 12792 KB Output is correct
5 Correct 250 ms 12404 KB Output is correct
6 Correct 251 ms 12792 KB Output is correct
7 Correct 260 ms 13304 KB Output is correct
8 Correct 253 ms 12920 KB Output is correct
9 Correct 258 ms 19576 KB Output is correct
10 Correct 260 ms 21256 KB Output is correct
11 Correct 248 ms 21244 KB Output is correct
12 Correct 254 ms 21496 KB Output is correct
13 Correct 242 ms 21240 KB Output is correct
14 Correct 240 ms 21240 KB Output is correct
15 Correct 246 ms 21240 KB Output is correct
16 Correct 113 ms 15352 KB Output is correct