Submission #152554

# Submission time Handle Problem Language Result Execution time Memory
152554 2019-09-08T11:50:55 Z cheetose Toll (BOI17_toll) C++11
100 / 100
294 ms 66324 KB
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

typedef vector<Vi> matrix;
matrix A[50000][16];
int k,n,m,q;
matrix mul(const matrix &M1,const matrix &M2){
	matrix M(k,Vi(k,INF));
	fup(kk,0,k-1,1)
		fup(i,0,k-1,1)fup(j,0,k-1,1)
		M[i][j]=min(M[i][j],M1[i][kk]+M2[kk][j]);
	return M;
}
matrix g(int x,int y)
{
	matrix M=A[x][0];
	x++;
	int t=y-x;
	fdn(i,15,0,1)
	{
		if(t&(1<<i))
		{
			M=mul(M,A[x][i]);
			x+=(1<<i);
		}
	}
	return M;
}
int main() {
	scanf("%d%d%d%d",&k,&n,&m,&q);
	fup(i,0,(n-1)/k,1)A[i][0].resize(k,Vi(k,INF));
	fup(i,0,m-1,1)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		A[x/k][0][x%k][y%k]=min(z,A[x/k][0][x%k][y%k]);
	}
	fup(j,0,14,1)
	{
		fup(i,0,(n-1)/k,1)
		{
			if(i+(1<<j)+1>(n-1)/k || A[i+(1<<j)][j].size()==0)break;
			A[i][j+1]=mul(A[i][j],A[i+(1<<j)][j]);
		}
	}
	while(q--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a/k==b/k)
		{
			puts("-1");
			continue;
		}
		matrix M=g(a/k,b/k);
		int ans=M[a%k][b%k];
		if(ans==INF)ans=-1;
		printf("%d\n",ans);
	}
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&k,&n,&m,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:94:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&x,&y,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~
toll.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 250 ms 65244 KB Output is correct
2 Correct 20 ms 19064 KB Output is correct
3 Correct 27 ms 19192 KB Output is correct
4 Correct 20 ms 19068 KB Output is correct
5 Correct 23 ms 19704 KB Output is correct
6 Correct 23 ms 19704 KB Output is correct
7 Correct 23 ms 19704 KB Output is correct
8 Correct 253 ms 66168 KB Output is correct
9 Correct 294 ms 66036 KB Output is correct
10 Correct 236 ms 65400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 62200 KB Output is correct
2 Correct 19 ms 19116 KB Output is correct
3 Correct 19 ms 19064 KB Output is correct
4 Correct 20 ms 19064 KB Output is correct
5 Correct 22 ms 19064 KB Output is correct
6 Correct 19 ms 19064 KB Output is correct
7 Correct 36 ms 19844 KB Output is correct
8 Correct 39 ms 19704 KB Output is correct
9 Correct 251 ms 66116 KB Output is correct
10 Correct 221 ms 58872 KB Output is correct
11 Correct 245 ms 63820 KB Output is correct
12 Correct 217 ms 57988 KB Output is correct
13 Correct 167 ms 41336 KB Output is correct
14 Correct 126 ms 41888 KB Output is correct
15 Correct 136 ms 40044 KB Output is correct
16 Correct 122 ms 40056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19036 KB Output is correct
2 Correct 20 ms 19064 KB Output is correct
3 Correct 19 ms 19064 KB Output is correct
4 Correct 19 ms 19036 KB Output is correct
5 Correct 19 ms 19060 KB Output is correct
6 Correct 21 ms 19708 KB Output is correct
7 Correct 22 ms 19576 KB Output is correct
8 Correct 23 ms 19576 KB Output is correct
9 Correct 22 ms 19576 KB Output is correct
10 Correct 212 ms 65936 KB Output is correct
11 Correct 191 ms 63616 KB Output is correct
12 Correct 207 ms 58616 KB Output is correct
13 Correct 206 ms 58872 KB Output is correct
14 Correct 180 ms 58360 KB Output is correct
15 Correct 111 ms 40056 KB Output is correct
16 Correct 112 ms 40056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19036 KB Output is correct
2 Correct 20 ms 19064 KB Output is correct
3 Correct 19 ms 19064 KB Output is correct
4 Correct 19 ms 19036 KB Output is correct
5 Correct 19 ms 19060 KB Output is correct
6 Correct 21 ms 19708 KB Output is correct
7 Correct 22 ms 19576 KB Output is correct
8 Correct 23 ms 19576 KB Output is correct
9 Correct 22 ms 19576 KB Output is correct
10 Correct 212 ms 65936 KB Output is correct
11 Correct 191 ms 63616 KB Output is correct
12 Correct 207 ms 58616 KB Output is correct
13 Correct 206 ms 58872 KB Output is correct
14 Correct 180 ms 58360 KB Output is correct
15 Correct 111 ms 40056 KB Output is correct
16 Correct 112 ms 40056 KB Output is correct
17 Correct 203 ms 63724 KB Output is correct
18 Correct 23 ms 19192 KB Output is correct
19 Correct 19 ms 19064 KB Output is correct
20 Correct 19 ms 19064 KB Output is correct
21 Correct 19 ms 19068 KB Output is correct
22 Correct 20 ms 19068 KB Output is correct
23 Correct 25 ms 19708 KB Output is correct
24 Correct 26 ms 19704 KB Output is correct
25 Correct 29 ms 19576 KB Output is correct
26 Correct 27 ms 19576 KB Output is correct
27 Correct 223 ms 66024 KB Output is correct
28 Correct 204 ms 58744 KB Output is correct
29 Correct 227 ms 59144 KB Output is correct
30 Correct 197 ms 58360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 65244 KB Output is correct
2 Correct 20 ms 19064 KB Output is correct
3 Correct 27 ms 19192 KB Output is correct
4 Correct 20 ms 19068 KB Output is correct
5 Correct 23 ms 19704 KB Output is correct
6 Correct 23 ms 19704 KB Output is correct
7 Correct 23 ms 19704 KB Output is correct
8 Correct 253 ms 66168 KB Output is correct
9 Correct 294 ms 66036 KB Output is correct
10 Correct 236 ms 65400 KB Output is correct
11 Correct 215 ms 62200 KB Output is correct
12 Correct 19 ms 19116 KB Output is correct
13 Correct 19 ms 19064 KB Output is correct
14 Correct 20 ms 19064 KB Output is correct
15 Correct 22 ms 19064 KB Output is correct
16 Correct 19 ms 19064 KB Output is correct
17 Correct 36 ms 19844 KB Output is correct
18 Correct 39 ms 19704 KB Output is correct
19 Correct 251 ms 66116 KB Output is correct
20 Correct 221 ms 58872 KB Output is correct
21 Correct 245 ms 63820 KB Output is correct
22 Correct 217 ms 57988 KB Output is correct
23 Correct 167 ms 41336 KB Output is correct
24 Correct 126 ms 41888 KB Output is correct
25 Correct 136 ms 40044 KB Output is correct
26 Correct 122 ms 40056 KB Output is correct
27 Correct 19 ms 19036 KB Output is correct
28 Correct 20 ms 19064 KB Output is correct
29 Correct 19 ms 19064 KB Output is correct
30 Correct 19 ms 19036 KB Output is correct
31 Correct 19 ms 19060 KB Output is correct
32 Correct 21 ms 19708 KB Output is correct
33 Correct 22 ms 19576 KB Output is correct
34 Correct 23 ms 19576 KB Output is correct
35 Correct 22 ms 19576 KB Output is correct
36 Correct 212 ms 65936 KB Output is correct
37 Correct 191 ms 63616 KB Output is correct
38 Correct 207 ms 58616 KB Output is correct
39 Correct 206 ms 58872 KB Output is correct
40 Correct 180 ms 58360 KB Output is correct
41 Correct 111 ms 40056 KB Output is correct
42 Correct 112 ms 40056 KB Output is correct
43 Correct 203 ms 63724 KB Output is correct
44 Correct 23 ms 19192 KB Output is correct
45 Correct 19 ms 19064 KB Output is correct
46 Correct 19 ms 19064 KB Output is correct
47 Correct 19 ms 19068 KB Output is correct
48 Correct 20 ms 19068 KB Output is correct
49 Correct 25 ms 19708 KB Output is correct
50 Correct 26 ms 19704 KB Output is correct
51 Correct 29 ms 19576 KB Output is correct
52 Correct 27 ms 19576 KB Output is correct
53 Correct 223 ms 66024 KB Output is correct
54 Correct 204 ms 58744 KB Output is correct
55 Correct 227 ms 59144 KB Output is correct
56 Correct 197 ms 58360 KB Output is correct
57 Correct 279 ms 59776 KB Output is correct
58 Correct 254 ms 66324 KB Output is correct
59 Correct 239 ms 63708 KB Output is correct