답안 #785045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785045 2023-07-17T01:41:59 Z tolbi Toll (BOI17_toll) C++17
100 / 100
119 ms 13268 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//ahmet23 orz...
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
//Sani buyuk Osman Pasa Plevneden cikmam diyor
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& is, pair<X,Y> &pr){return is>>pr.first>>pr.second;}
#ifdef tolbi
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr){return os<<"{ "<<pr.first<<", "<<pr.second<<" }";}
#else
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr){return os<<pr.first<<" "<<pr.second;}
#endif
ostream& operator<<(ostream& os, bool bl){return os<<(int32_t)bl;}
template<typename X> istream& operator>>(istream& is, vector<X> &arr){for (auto &it : arr) is>>it; return is;}
template<typename X, size_t Y> istream& operator>>(istream& is, array<X,Y> &arr){for (auto &it : arr) is>>it; return is;}
template<typename X> ostream& operator<<(ostream& os, vector<X> &arr){for (auto &it : arr) os<<" "<<it;os<<endl;return os;}
template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> &arr){for (auto &it : arr) os<<" "<<it;os<<endl;return os;}
#define int long long
#define endl '\n'
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for(auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(), x.end())
#define sortrarr(x) sort(x.rbegin(), x.rend())
#define rev(x) reverse(x.begin(), x.end())
#define tol(bi) (1LL<<((int)(bi)))
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = LONG_LONG_MAX;
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
vector<vector<vector<int>>> segtree;
vector<vector<int>> bos;
vector<vector<int>> neg;
int k;
void merge(int node){
	int left = node*2+1;
	int right = node*2+2;
	for (int i = 0; i < k; i++){
		for (int j = 0; j < k; j++){
			for (int z = 0; z < k; z++){
				if (segtree[left][i][z]==-1 || segtree[right][z][j]==-1) continue;
				int crr = segtree[left][i][z]+segtree[right][z][j];
				if (segtree[node][i][j]==-1){
					segtree[node][i][j]=crr;
				}
				else {
					segtree[node][i][j]=min(segtree[node][i][j],crr);
				}
			}
		}
	}
}
vector<vector<int>> query(int tarl, int tarr, int l = 0, int r = segtree.size()/2, int node = 0){
	if (l>=tarl && r<=tarr) return segtree[node];
	if (l>tarr || r<tarl) return bos;
	int mid = l+(r-l)/2;
	vector<vector<int>> lnode = query(tarl, tarr, l, mid, node*2+1);
	vector<vector<int>> rnode = query(tarl, tarr, mid+1, r, node*2+2);
	vector<vector<int>> res = neg;
	if (lnode[0][0]==-2) return rnode;
	if (rnode[0][0]==-2) return lnode;
	for (int i = 0; i < k; i++){
		for (int j = 0; j < k; j++){
			for (int z = 0; z < k; z++){
				if (lnode[i][z]==-1 || rnode[z][j]==-1) continue;
				int crr = lnode[i][z]+rnode[z][j];
				if (res[i][j]==-1){
					res[i][j]=crr;
				}
				else {
					res[i][j]=min(res[i][j],crr);
				}
			}
		}
	}
	return res;
}
//update olsa onu da yaparduk da soru fazla kolay lol
int32_t main(){
	ios;
	int T = 1;
	if (!T) cin>>T;
	int tno = 0;
	while (T-(tno++)){
		cin>>k;deci(n);deci(m);deci(q);
		segtree.resize(tol(ceil(log2((n+k-1)/k)+1))-1,vector<vector<int>>(k,vector<int>(k,-1)));
		bos.resize(k,vector<int>(k,-2));
		neg.resize(k,vector<int>(k,-1));
		for (int i = 0; i < m; ++i)
		{
			deci(a);deci(b);deci(x);
			segtree[a/k+segtree.size()/2][a%k][b%k]=x;
		}
		for (int i = segtree.size()/2-1; i >= 0; i--){
			merge(i);
		}
		while (q--){
			deci(a);deci(b);
			if (a==b){
				cout<<0<<endl;
				continue;
			}
			if (b/k<=a/k){
				cout<<-1<<endl;
				continue;
			}
			vector<vector<int>> res = query(a/k,b/k-1);
			if (res[a%k][b%k]==-1){
				cout<<-1<<endl;
			}
			else {
				cout<<res[a%k][b%k]<<endl;
			}
		}
	}
}

Compilation message

toll.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11664 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 3 ms 524 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 51 ms 11880 KB Output is correct
9 Correct 45 ms 11868 KB Output is correct
10 Correct 37 ms 11732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 10108 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 580 KB Output is correct
8 Correct 16 ms 596 KB Output is correct
9 Correct 46 ms 11744 KB Output is correct
10 Correct 68 ms 13264 KB Output is correct
11 Correct 56 ms 10232 KB Output is correct
12 Correct 59 ms 13268 KB Output is correct
13 Correct 53 ms 6736 KB Output is correct
14 Correct 34 ms 6872 KB Output is correct
15 Correct 37 ms 6740 KB Output is correct
16 Correct 49 ms 6752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 21 ms 11604 KB Output is correct
11 Correct 28 ms 10068 KB Output is correct
12 Correct 40 ms 13140 KB Output is correct
13 Correct 44 ms 13148 KB Output is correct
14 Correct 37 ms 13140 KB Output is correct
15 Correct 26 ms 6620 KB Output is correct
16 Correct 34 ms 6620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 284 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 21 ms 11604 KB Output is correct
11 Correct 28 ms 10068 KB Output is correct
12 Correct 40 ms 13140 KB Output is correct
13 Correct 44 ms 13148 KB Output is correct
14 Correct 37 ms 13140 KB Output is correct
15 Correct 26 ms 6620 KB Output is correct
16 Correct 34 ms 6620 KB Output is correct
17 Correct 50 ms 10068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 5 ms 468 KB Output is correct
24 Correct 7 ms 468 KB Output is correct
25 Correct 13 ms 532 KB Output is correct
26 Correct 10 ms 468 KB Output is correct
27 Correct 29 ms 11604 KB Output is correct
28 Correct 72 ms 13172 KB Output is correct
29 Correct 56 ms 13164 KB Output is correct
30 Correct 49 ms 13140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11664 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 3 ms 524 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 51 ms 11880 KB Output is correct
9 Correct 45 ms 11868 KB Output is correct
10 Correct 37 ms 11732 KB Output is correct
11 Correct 48 ms 10108 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 10 ms 580 KB Output is correct
18 Correct 16 ms 596 KB Output is correct
19 Correct 46 ms 11744 KB Output is correct
20 Correct 68 ms 13264 KB Output is correct
21 Correct 56 ms 10232 KB Output is correct
22 Correct 59 ms 13268 KB Output is correct
23 Correct 53 ms 6736 KB Output is correct
24 Correct 34 ms 6872 KB Output is correct
25 Correct 37 ms 6740 KB Output is correct
26 Correct 49 ms 6752 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 284 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 21 ms 11604 KB Output is correct
37 Correct 28 ms 10068 KB Output is correct
38 Correct 40 ms 13140 KB Output is correct
39 Correct 44 ms 13148 KB Output is correct
40 Correct 37 ms 13140 KB Output is correct
41 Correct 26 ms 6620 KB Output is correct
42 Correct 34 ms 6620 KB Output is correct
43 Correct 50 ms 10068 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 5 ms 468 KB Output is correct
50 Correct 7 ms 468 KB Output is correct
51 Correct 13 ms 532 KB Output is correct
52 Correct 10 ms 468 KB Output is correct
53 Correct 29 ms 11604 KB Output is correct
54 Correct 72 ms 13172 KB Output is correct
55 Correct 56 ms 13164 KB Output is correct
56 Correct 49 ms 13140 KB Output is correct
57 Correct 119 ms 11020 KB Output is correct
58 Correct 46 ms 11700 KB Output is correct
59 Correct 62 ms 10200 KB Output is correct