답안 #29079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29079 2017-07-18T08:06:02 Z 윤교준(#1173) Railway Trip (JOI17_railway_trip) C++11
5 / 100
3 ms 2064 KB
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define MAXN (105)
#define MAXQ (55)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

int d[MAXN][MAXN];
int A[MAXN];
int S[MAXQ], E[MAXQ];
int N, K, Q;

int main() {
	scanf("%d%d%d", &N, &K, &Q);
	for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
	for(int i = 0; i < Q; i++) scanf("%d%d", &S[i], &E[i]);
	for(int i = 1; i <= N; i++) fill(d[i], d[i]+N+1, INF);
	for(int i = 1; i <= N; i++) d[i][i] = 0;
	for(int i = 1; i <= K; i++) {
		vector<int> V;
		for(int j = 1; j <= N; j++) if(i <= A[j]) V.pb(j);
		for(int a = 0; a < sz(V); a++) for(int b = a+1; b < sz(V); b++) {
			upmin(d[V[a]][V[b]], b-a);
			upmin(d[V[b]][V[a]], b-a);
		}
	}
	for(int k = 1; k <= N; k++) for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++)
		upmin(d[i][j], d[i][k] + d[k][j]);
	for(int i = 0; i < Q; i++) printf("%d\n", d[S[i]][E[i]] - 1);
	return 0;
}

Compilation message

railway_trip.cpp: In function 'int main()':
railway_trip.cpp:27:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &K, &Q);
                             ^
railway_trip.cpp:28:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= N; i++) scanf("%d", &A[i]);
                                                ^
railway_trip.cpp:29:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < Q; i++) scanf("%d%d", &S[i], &E[i]);
                                                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2064 KB Output is correct
2 Correct 3 ms 2064 KB Output is correct
3 Correct 0 ms 2064 KB Output is correct
4 Correct 0 ms 2064 KB Output is correct
5 Correct 0 ms 2064 KB Output is correct
6 Correct 0 ms 2064 KB Output is correct
7 Correct 3 ms 2064 KB Output is correct
8 Correct 0 ms 2064 KB Output is correct
9 Correct 0 ms 2064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2064 KB Execution killed because of forbidden syscall futex (202)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2064 KB Execution killed because of forbidden syscall futex (202)
2 Halted 0 ms 0 KB -