답안 #696060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696060 2023-02-05T09:41:35 Z vjudge1 Toll (BOI17_toll) C++17
100 / 100
391 ms 176540 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "tnc"  
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k,m,o;
struct Matrix{
	ll a[5][5];
	Matrix(){
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				a[i][j]=1e9;
			}
		}
	}
	Matrix operator+(const Matrix&b){
		Matrix res;
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				res.a[i][j]=1e9;
				for(int z=0;z<5;z++){
					res.a[i][j]=min(res.a[i][j],a[i][z]+b.a[z][j]);
				}
			}
		}
		return res;
	}
};
Matrix d[50005][18];
signed main()
{
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    //freopen(task".inp" , "r" , stdin);
    //freopen(task".out" , "w" , stdout);
    cin>>k>>n>>m>>o;
    for(int i=1;i<=m;i++){
    	int a,b,t;
    	cin>>a>>b>>t;
    	d[a/k][0].a[a%k][b%k]=t;
    }
    int sl=(n+k-1)/k;
    for(int i=1;(1<<i)<=n;i++){
    	for(int j=0;j+(1<<i)-1<=n;j++){
    		d[j][i]=d[j][i-1]+d[j+(1<<(i-1))][i-1];
    	}
    }
    for(int i=1;i<=o;i++){
    	int a,b;
    	cin>>a>>b;
    	Matrix s;
    	for(int j=0;j<5;j++){
    		s.a[j][j]=0;
    		
    	}
    	if(a==b){
    		cout<<0<<"\n";
    		continue;
    	}
    	int lop=a/k;
    	int lop1=b/k;
    	if(lop1<=lop){
    		cout<<-1<<"\n";
    	}
    	else{
    		int hieu=lop1-lop;
    		for(int j=16;j>=0;j--){
    			if((1<<j)&hieu){
    				s=s+d[lop][j];
    				lop+=(1<<j);
    			}
    		}
    		if(s.a[a%k][b%k]==1e9)cout<<-1<<"\n";
    		else cout<<s.a[a%k][b%k]<<"\n";
    	}
    }
    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:65:9: warning: unused variable 'sl' [-Wunused-variable]
   65 |     int sl=(n+k-1)/k;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 176448 KB Output is correct
2 Correct 80 ms 176424 KB Output is correct
3 Correct 72 ms 176396 KB Output is correct
4 Correct 73 ms 176376 KB Output is correct
5 Correct 88 ms 176408 KB Output is correct
6 Correct 71 ms 176436 KB Output is correct
7 Correct 69 ms 176460 KB Output is correct
8 Correct 294 ms 176440 KB Output is correct
9 Correct 283 ms 176444 KB Output is correct
10 Correct 317 ms 176448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 324 ms 176460 KB Output is correct
2 Correct 73 ms 176376 KB Output is correct
3 Correct 84 ms 176392 KB Output is correct
4 Correct 79 ms 176416 KB Output is correct
5 Correct 74 ms 176348 KB Output is correct
6 Correct 68 ms 176400 KB Output is correct
7 Correct 92 ms 176472 KB Output is correct
8 Correct 93 ms 176444 KB Output is correct
9 Correct 273 ms 176396 KB Output is correct
10 Correct 297 ms 176540 KB Output is correct
11 Correct 293 ms 176448 KB Output is correct
12 Correct 293 ms 176444 KB Output is correct
13 Correct 225 ms 176460 KB Output is correct
14 Correct 207 ms 176452 KB Output is correct
15 Correct 203 ms 176448 KB Output is correct
16 Correct 212 ms 176476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 176332 KB Output is correct
2 Correct 69 ms 176368 KB Output is correct
3 Correct 76 ms 176428 KB Output is correct
4 Correct 73 ms 176328 KB Output is correct
5 Correct 75 ms 176484 KB Output is correct
6 Correct 72 ms 176376 KB Output is correct
7 Correct 72 ms 176328 KB Output is correct
8 Correct 74 ms 176364 KB Output is correct
9 Correct 86 ms 176364 KB Output is correct
10 Correct 300 ms 176452 KB Output is correct
11 Correct 300 ms 176448 KB Output is correct
12 Correct 286 ms 176376 KB Output is correct
13 Correct 287 ms 176444 KB Output is correct
14 Correct 277 ms 176448 KB Output is correct
15 Correct 193 ms 176484 KB Output is correct
16 Correct 196 ms 176448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 176332 KB Output is correct
2 Correct 69 ms 176368 KB Output is correct
3 Correct 76 ms 176428 KB Output is correct
4 Correct 73 ms 176328 KB Output is correct
5 Correct 75 ms 176484 KB Output is correct
6 Correct 72 ms 176376 KB Output is correct
7 Correct 72 ms 176328 KB Output is correct
8 Correct 74 ms 176364 KB Output is correct
9 Correct 86 ms 176364 KB Output is correct
10 Correct 300 ms 176452 KB Output is correct
11 Correct 300 ms 176448 KB Output is correct
12 Correct 286 ms 176376 KB Output is correct
13 Correct 287 ms 176444 KB Output is correct
14 Correct 277 ms 176448 KB Output is correct
15 Correct 193 ms 176484 KB Output is correct
16 Correct 196 ms 176448 KB Output is correct
17 Correct 280 ms 176444 KB Output is correct
18 Correct 73 ms 176416 KB Output is correct
19 Correct 86 ms 176416 KB Output is correct
20 Correct 70 ms 176340 KB Output is correct
21 Correct 68 ms 176404 KB Output is correct
22 Correct 74 ms 176400 KB Output is correct
23 Correct 91 ms 176372 KB Output is correct
24 Correct 76 ms 176408 KB Output is correct
25 Correct 84 ms 176348 KB Output is correct
26 Correct 75 ms 176440 KB Output is correct
27 Correct 278 ms 176376 KB Output is correct
28 Correct 291 ms 176456 KB Output is correct
29 Correct 317 ms 176444 KB Output is correct
30 Correct 294 ms 176452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 176448 KB Output is correct
2 Correct 80 ms 176424 KB Output is correct
3 Correct 72 ms 176396 KB Output is correct
4 Correct 73 ms 176376 KB Output is correct
5 Correct 88 ms 176408 KB Output is correct
6 Correct 71 ms 176436 KB Output is correct
7 Correct 69 ms 176460 KB Output is correct
8 Correct 294 ms 176440 KB Output is correct
9 Correct 283 ms 176444 KB Output is correct
10 Correct 317 ms 176448 KB Output is correct
11 Correct 324 ms 176460 KB Output is correct
12 Correct 73 ms 176376 KB Output is correct
13 Correct 84 ms 176392 KB Output is correct
14 Correct 79 ms 176416 KB Output is correct
15 Correct 74 ms 176348 KB Output is correct
16 Correct 68 ms 176400 KB Output is correct
17 Correct 92 ms 176472 KB Output is correct
18 Correct 93 ms 176444 KB Output is correct
19 Correct 273 ms 176396 KB Output is correct
20 Correct 297 ms 176540 KB Output is correct
21 Correct 293 ms 176448 KB Output is correct
22 Correct 293 ms 176444 KB Output is correct
23 Correct 225 ms 176460 KB Output is correct
24 Correct 207 ms 176452 KB Output is correct
25 Correct 203 ms 176448 KB Output is correct
26 Correct 212 ms 176476 KB Output is correct
27 Correct 77 ms 176332 KB Output is correct
28 Correct 69 ms 176368 KB Output is correct
29 Correct 76 ms 176428 KB Output is correct
30 Correct 73 ms 176328 KB Output is correct
31 Correct 75 ms 176484 KB Output is correct
32 Correct 72 ms 176376 KB Output is correct
33 Correct 72 ms 176328 KB Output is correct
34 Correct 74 ms 176364 KB Output is correct
35 Correct 86 ms 176364 KB Output is correct
36 Correct 300 ms 176452 KB Output is correct
37 Correct 300 ms 176448 KB Output is correct
38 Correct 286 ms 176376 KB Output is correct
39 Correct 287 ms 176444 KB Output is correct
40 Correct 277 ms 176448 KB Output is correct
41 Correct 193 ms 176484 KB Output is correct
42 Correct 196 ms 176448 KB Output is correct
43 Correct 280 ms 176444 KB Output is correct
44 Correct 73 ms 176416 KB Output is correct
45 Correct 86 ms 176416 KB Output is correct
46 Correct 70 ms 176340 KB Output is correct
47 Correct 68 ms 176404 KB Output is correct
48 Correct 74 ms 176400 KB Output is correct
49 Correct 91 ms 176372 KB Output is correct
50 Correct 76 ms 176408 KB Output is correct
51 Correct 84 ms 176348 KB Output is correct
52 Correct 75 ms 176440 KB Output is correct
53 Correct 278 ms 176376 KB Output is correct
54 Correct 291 ms 176456 KB Output is correct
55 Correct 317 ms 176444 KB Output is correct
56 Correct 294 ms 176452 KB Output is correct
57 Correct 324 ms 176448 KB Output is correct
58 Correct 317 ms 176448 KB Output is correct
59 Correct 391 ms 176468 KB Output is correct