# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
1022745 | | pan | Toll (BOI17_toll) | C++17 | | 107 ms | 88912 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i)
#define RFOR(i, x, n) for (ll i =x; i>=n; --i)
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;
ll INF = 1e13;
vector<pi> adj[50005];
ll n, m, q, a, b, t;
ll blksize = 0, blk = 0;
struct block
{
ll l, r;
ll dp[10][10];
block(ll _l =0, ll _r = 0)
{
l = _l, r = _r;
for (ll i=0; i<=blksize; ++i) for (ll j=0; j<=blksize; ++j) dp[i][j] = INF;
if (_l == _r) for (ll i=0; i<=blksize; ++i) dp[i][i] = 0;
}
block operator + (const block & other)
{
block ret = block(l, other.r);
//cout << "combine " << l << ' ' << r << ' '<< other.l << ' ' << other.r << endl;
for (ll i = r*blksize; i < min(n, (r+1)*blksize); ++i)
{
for (pi u: adj[i])
{
//show2(i, u.f);
for (ll j=0; j<blksize; ++j) for (ll k=0; k<blksize; ++k)
{
ret.dp[j][k] = min(ret.dp[j][k], dp[j][i - blksize*r] + u.s + other.dp[u.f - blksize*other.l][k]);
}
}
}
return ret;
}
};
struct node {
int s, e, m;
block val;
node * l, * r;
node(int S, int E) {
s = S, e = E, m = (s + e) / 2;
if (s != e) {
l = new node(s, m);
r = new node(m + 1, e);
val = l->val + r->val;
}
else
{
l = r = nullptr;
val = block(s, s);
}
}
block query(int S, int E) {
if (s == S && e == E) return val;
else if (E <= m) return l -> query(S, E);
else if (S >= m + 1) return r -> query(S, E);
else return l -> query(S, m) + r -> query(m + 1, E);
}
}* root;
int main()
{
input4(blksize, n, m, q);
blk = (n-1)/blksize;
//show(blk);
for (ll i=0; i<m ; ++i)
{
input3(a, b, t);
adj[a].pb(mp(b,t));
}
root = new node(0, blk);
while (q--)
{
input2(a, b);
ll aa = a/blksize, bb = b/blksize;
//show2(aa, bb);
block ret = root->query(aa, bb);
ll ans = ret.dp[a - aa*blksize][b - bb*blksize];
print( ((ans==INF)?-1LL:ans), '\n');
}
return 0;
}
Compilation message (stderr)
toll.cpp: In function 'int main()':
toll.cpp:15:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | #define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:106:2: note: in expansion of macro 'input4'
106 | input4(blksize, n, m, q);
| ^~~~~~
toll.cpp:14:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:111:3: note: in expansion of macro 'input3'
111 | input3(a, b, t);
| ^~~~~~
toll.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
toll.cpp:117:3: note: in expansion of macro 'input2'
117 | input2(a, b);
| ^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |