답안 #210479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210479 2020-03-17T13:46:15 Z hanagasumi Railway Trip (JOI17_railway_trip) C++17
5 / 100
2000 ms 524292 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>

#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll

using namespace std;
typedef long long ll;
typedef long double ld;

int inf = 1e9 + 100;

signed main() {
	#ifdef PC
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, k, q;
	cin >> n >> k >> q;
	vector<int> l(n);
	vector<vector<int>> g(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	vector<int> was(k + 1, -1);
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 1; j <= l[i]; j++) {
			if(was[j] == -1) 
				continue;
			g[i].pb(was[j]);
		}
		for (int j = 1; j <= l[i]; j++)
			was[j] = i;
	}
	was = vector<int> (k + 1, -1);
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= l[i]; j++) {
			if(was[j] == -1) 
				continue;
			g[i].pb(was[j]);
		}
		for (int j = 1; j <= l[i]; j++)
			was[j] = i;
	}

	vector<vector<int>> dst(n, vector<int> (n, inf));
	for (int i = 0; i < n; i++) {
		dst[i][i] = 0;
		deque<int> q;
		q.pb(i);
		while(len(q) > 0) {
			auto now = q.front();
			q.pop_front();
			for (auto x : g[now]) {
				if(dst[i][x] != inf) 
					continue;
				dst[i][x] = dst[i][now] + 1;
				q.pb(x);
			}
		}
	}
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		cout << dst[a][b] - 1 << '\n';
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 504 KB Output is correct
2 Correct 7 ms 504 KB Output is correct
3 Correct 7 ms 504 KB Output is correct
4 Correct 7 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 9 ms 632 KB Output is correct
7 Correct 10 ms 632 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2096 ms 19064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 350 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 617 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -