답안 #776218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776218 2023-07-07T13:06:26 Z MasterTaster Toll (BOI17_toll) C++14
100 / 100
1743 ms 5036 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 50010

using namespace std;

int n, m, k, q;
//map<pair<pii, pii>, int> dp;
int w[MAXN][6], ress[MAXN];

/*int resi(int a, int b, int x, int y)
{
	if (dp[{{a, b}, {x, y}}]) return dp[{{a, b}, {x, y}}];
	if ((a+1)==b) return 1000000010;

	int mid=a+(b-a)/2;
	int ress=1000000010;
	for (int i=0; i<k; i++)
	{
		ress=min(ress, resi(a, mid, x, i)+resi(mid, b, i, y));
	}

	dp[{{a, b}, {x, y}}]=ress;
	return ress;
}*/

int main(){
	cin>>k>>n>>m>>q;

	for (int i=0; i<n; i++) for (int j=0; j<k; j++) w[i][j]=1000000010;
	for (int i=0; i<m; i++)
	{
		int u, v, t; cin>>u>>v>>t;
		w[u][v%k]=t;
	}

	while (q--)
	{
		int x, y; cin>>x>>y;

		for (int i=x; i<=y; i++) ress[i]=1000000010;
		ress[x]=0;

		for (int i=x; i<(y/k)*k; i++)
		{
			for (int j=0; j<k; j++)
			{
				ress[((i/k)+1)*k+j]=min(ress[((i/k)+1)*k+j], ress[i]+w[i][j]);
				//cout<<i<<" do "<<((i/k)+1)*k+j<<" kosta "<<ress[((i/k)+1)*k+j]<<endl;
			}
		}

		if (ress[y]>=1000000010) cout<<-1<<"\n";
		else cout<<ress[y]<<"\n";

	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1211 ms 2496 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 320 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 1196 ms 2704 KB Output is correct
9 Correct 1190 ms 2556 KB Output is correct
10 Correct 1166 ms 1796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1743 ms 3012 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 43 ms 420 KB Output is correct
8 Correct 43 ms 460 KB Output is correct
9 Correct 1720 ms 2588 KB Output is correct
10 Correct 1705 ms 3984 KB Output is correct
11 Correct 1724 ms 3412 KB Output is correct
12 Correct 1662 ms 2964 KB Output is correct
13 Correct 387 ms 3520 KB Output is correct
14 Correct 348 ms 2640 KB Output is correct
15 Correct 348 ms 2324 KB Output is correct
16 Correct 375 ms 2264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 320 KB Output is correct
10 Correct 40 ms 2400 KB Output is correct
11 Correct 64 ms 3112 KB Output is correct
12 Correct 83 ms 3744 KB Output is correct
13 Correct 92 ms 4012 KB Output is correct
14 Correct 73 ms 3396 KB Output is correct
15 Correct 49 ms 2272 KB Output is correct
16 Correct 47 ms 2248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 320 KB Output is correct
10 Correct 40 ms 2400 KB Output is correct
11 Correct 64 ms 3112 KB Output is correct
12 Correct 83 ms 3744 KB Output is correct
13 Correct 92 ms 4012 KB Output is correct
14 Correct 73 ms 3396 KB Output is correct
15 Correct 49 ms 2272 KB Output is correct
16 Correct 47 ms 2248 KB Output is correct
17 Correct 392 ms 3368 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 11 ms 316 KB Output is correct
24 Correct 12 ms 408 KB Output is correct
25 Correct 13 ms 340 KB Output is correct
26 Correct 12 ms 340 KB Output is correct
27 Correct 381 ms 2500 KB Output is correct
28 Correct 402 ms 3884 KB Output is correct
29 Correct 416 ms 4120 KB Output is correct
30 Correct 413 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1211 ms 2496 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 320 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 1196 ms 2704 KB Output is correct
9 Correct 1190 ms 2556 KB Output is correct
10 Correct 1166 ms 1796 KB Output is correct
11 Correct 1743 ms 3012 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 43 ms 420 KB Output is correct
18 Correct 43 ms 460 KB Output is correct
19 Correct 1720 ms 2588 KB Output is correct
20 Correct 1705 ms 3984 KB Output is correct
21 Correct 1724 ms 3412 KB Output is correct
22 Correct 1662 ms 2964 KB Output is correct
23 Correct 387 ms 3520 KB Output is correct
24 Correct 348 ms 2640 KB Output is correct
25 Correct 348 ms 2324 KB Output is correct
26 Correct 375 ms 2264 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 2 ms 320 KB Output is correct
36 Correct 40 ms 2400 KB Output is correct
37 Correct 64 ms 3112 KB Output is correct
38 Correct 83 ms 3744 KB Output is correct
39 Correct 92 ms 4012 KB Output is correct
40 Correct 73 ms 3396 KB Output is correct
41 Correct 49 ms 2272 KB Output is correct
42 Correct 47 ms 2248 KB Output is correct
43 Correct 392 ms 3368 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 308 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 304 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 11 ms 316 KB Output is correct
50 Correct 12 ms 408 KB Output is correct
51 Correct 13 ms 340 KB Output is correct
52 Correct 12 ms 340 KB Output is correct
53 Correct 381 ms 2500 KB Output is correct
54 Correct 402 ms 3884 KB Output is correct
55 Correct 416 ms 4120 KB Output is correct
56 Correct 413 ms 3404 KB Output is correct
57 Correct 1199 ms 5036 KB Output is correct
58 Correct 1180 ms 2608 KB Output is correct
59 Correct 1200 ms 3364 KB Output is correct