Submission #952962

#TimeUsernameProblemLanguageResultExecution timeMemory
952962cpptowinToll (BOI17_toll)C++17
100 / 100
287 ms177512 KiB
#include<bits/stdc++.h> #define fo(i,d,c) for(int i=d;i<=c;i++) #define fod(i,c,d) for(int i=c;i>=d;i--) #define maxn 1000010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout<<"\n"; #define int long long #define inf (int)1e18 #define pii pair<int,int> #define vii vector<pii> #define lb(x) x&-x #define bit(i,j) ((i>>j)&1) #define offbit(i,j) (i^(1<<j)) #define onbit(i,j) (i|(1<<j)) #define vi vector<int> template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;} using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; int f[50010][18][5][5]; int ans[5][5],now[5][5]; int n,k,m,q; void combine(int ans[5][5],int a[5][5],int b[5][5]) { fo(i,0,4) fo(j,0,4) fo(k,0,4) ans[i][j] = min(ans[i][j],a[i][k] + b[k][j]); } main() { #define name "TASK" if(fopen(name".inp","r")) { freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> k >> n >> m >> q; fo(i,0,n / k) fo(j,0,17) fo(x,0,4) fo(y,0,4) f[i][j][x][y] = inf; fo(i,1,m) { int u,v,w; cin >> u >> v >> w; f[u / k][0][u % k][v % k] = w; } fo(j,1,17) fo(i,0,(n + k - 1) / k - (1 << j)) combine(f[i][j],f[i][j - 1],f[i + (1 << (j - 1))][j - 1]); while(q--) { fo(i,0,4) fo(j,0,4) ans[i][j] = inf; fo(i,0,4) ans[i][i] = 0; int u,v; cin >> u >> v; int U = u / k,V = v / k; int del = V - U; fod(i,17,0) if(bit(del,i)) { fo(j,0,4) fo(k,0,4) now[j][k] = inf; combine(now,ans,f[U][i]); memcpy(ans,now,sizeof ans); U = U + (1 << i); } cout << (ans[u % k][v % k] == inf ? -1 : ans[u % k][v % k]);en; } }

Compilation message (stderr)

toll.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main()
      | ^~~~
toll.cpp: In function 'int main()':
toll.cpp:36:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:37:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...