Submission #1003874

#TimeUsernameProblemLanguageResultExecution timeMemory
1003874tien_07Toll (BOI17_toll)C++17
0 / 100
58 ms120200 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define fi first #define se second #define pb push_back #define all(a) a.begin(),a.end() #define ms(a,n) memset(a,n,sizeof(a)) #define FOR(i,a,b) for(int i = a; i <= b; i++) #define FOD(i,b,a) for(int i = b; i >= a; i--) //Bit #define MASK(x) (1ll<<(x)) #define BIT(mask, i) (((mask) >> (i))&1) #define SET_ON(x,i) ((x) | MASK(i)) #define SET_OFF(x,i) ((x) & ~MASK(i)) #define c_bit(i) __builtin_popcountll(i) #define TASK "test" typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> ii; typedef pair<ii,int> iii; typedef pair<double,double> dd; typedef vector<ll> vll; typedef vector<int> vi; inline ll gcd(ll a, ll b){return b==0 ? a : gcd(b,a%b);} inline ll lcm(ll a, ll b){return a/gcd(a,b)*b;} const ld PI = 3.141592653589793238462643383279502884L; const int MOD = 1e9+7; const ll LINF = 1e18; const int INF = 1e9; const int N = 5e4+5; const int LOG = __lg(N)+5; int k,n,m,q; int dp[50000][17][6][6], ans[6][6], tmp[6][6]; void combine(int target[6][6], int a[6][6], int b[6][6]) { for (int x = 0; x < k; x++) { for (int y = 0; y < k; y++) { for (int z = 0; z < k; z++) { target[x][y] = min(target[x][y], a[x][z] + b[z][y]); } } } } void solve() { cin >> k >> n >> m >> q; memset(dp, 0x3f, sizeof dp); while (m--) { int a, b, t; cin >> a >> b >> t; dp[a / k][0][a % k][b % k] = t; } FOR(j,1,16){ for (int i = 0; i + (1 << j) < (n + k - 1) / k; i++) { combine(dp[i][j], dp[i][j - 1], dp[i + MASK(j) -1][j - 1]); } } while (q--) { int a, b; cin >> a >> b; memset(ans, 0x3f, sizeof ans); for (int i = 0; i < 5; i++) ans[i][i] = 0; for (int curr = a / k, dest = b / k, i = 16; ~i; i--) { if (curr + (1 << i) <= dest) { memset(tmp, 0x3f, sizeof tmp); combine(tmp, ans, dp[curr][i]); memcpy(ans, tmp, sizeof ans); curr += (1 << i); } } cout << (ans[a % k][b % k] >= 0x3f3f3f3f ? -1 : ans[a % k][b % k]) << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(TASK ".inp", "r", stdin); //freopen(TASK ".out", "w", stdout); int tc = 1; //cin >> tc; while (tc--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...