QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545198 | #32. Toll | Dimash | 0 | 1ms | 5960kb | C++17 | 2.8kb | 2024-09-03 00:54:56 | 2024-09-03 00:54:57 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e4 + 12, MOD = (int)1e9 + 7;
int k, n, m, q, b;
vector<pair<int,int>> g[N], o;
vector<ll> di[N];
const int inf = 1e9 + 1;
vector<ll> tr(vector<ll> prev,int l, int r) {
vector<ll> ret(k,inf);
assert(l % k == 0);
for(int i = l; i <= r; i++) {
int f = i % k;
for(auto [to,w]:g[i]) {
ret[to % k] = min(ret[to % k],prev[f] + w);
}
}
return ret;
}
void prec() {
for(int i = (int)o.size() - 1; i >= 0; i--) {
if(i % b == 0) {
int nx = i + b;
int l = o[i].first, r = o[i].second;
for(int j = l; j <= r; j++) {
vector<ll> dd(k,inf);
dd[j%k] = 0;
for(int _i = i + 1; _i < (int)o.size(); _i++) {
vector<ll> nv = tr(dd,o[_i - 1].first,o[_i - 1].second);
for(auto f:nv) {
di[j].push_back(f);
}
dd = nv;
}
}
}
}
}
void test() {
cin >> k >> n >> m >> q;
for(int i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
g[a].push_back({b,c});
}
for(int i = 0; i <= n; i++) {
int l = i * k, r = (i + 1) * k - 1;
if(l >= n) break;
if(r >= n) {
r = n - 1;
}
o.push_back({l,r});
}
for(int i = 0; i < n; i++) {
sort(g[i].begin(),g[i].end());
vector<pair<int,int>> nv;
for(auto [x,y]:g[i]) {
if(nv.empty() || nv.back().first != x) {
nv.emplace_back(x,y);
}
}
g[i].swap(nv);
assert((int)g[i].size() <= k);
}
b = 500;
b = 1;
prec();
// return;
while(q--) {
int a, b;
cin >> a >> b;
if(a / k >= b / k) {
cout << -1 << '\n';
continue;
}
int x = a / k, y = b / k;
vector<ll> cur(k,inf);
cur[a%k] = 0;
while(x % b != 0) {
x++;
cur = tr(cur,o[x - 1].first,o[x - 1].second);
if(x == y) {
break;
}
}
ll res = inf;
if(x == y) {
res = cur[y % k];
} else {
for(int i = 0; i < k; i++) {
int nx = (x + 1) * k;
res = min(res,di[o[x].first + i][b - nx] + cur[i]);
}
}
if(res == inf) res = -1;
cout << res << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
1 50000 49999 10000 28116 28117 4272 15866 15867 5673 38118 38119 8922 38575 38576 806 26221 26222 8045 16395 16396 211 17070 17071 1801 24810 24811 6670 44898 44899 6603 36986 36987 5958 5058 5059 5472 38952 38953 7947 25479 25480 937 34813 34814 8087 36873 36874 9102 38090 38091 4416 43253 43254 5...
output:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
2 50000 94996 10000 42590 42592 9309 11538 11541 4653 45675 45677 3309 869 870 6588 30563 30565 8686 30988 30991 9038 4495 4497 5335 25643 25644 6179 4890 4892 7897 18593 18594 2267 23266 23268 3778 42163 42164 8391 560 562 3808 48478 48480 7402 29601 29603 6345 42660 42662 6049 34298 34301 8993 152...
output:
result:
Subtask #3:
score: 0
Wrong Answer
Test #27:
score: 8
Accepted
time: 1ms
memory: 5868kb
input:
1 10 8 10 7 8 2626 0 1 4605 3 4 1319 4 5 1214 5 6 4454 6 7 4600 8 9 6857 1 2 2017 3 4 2 9 0 7 0 5 4 5 1 8 4 6 7 8 1 2 4 6
output:
1319 -1 -1 -1 1214 -1 5668 2626 2017 5668
result:
ok 10 lines
Test #28:
score: 0
Wrong Answer
time: 1ms
memory: 5960kb
input:
2 10 14 10 3 4 5032 0 2 6758 6 9 3324 0 3 2553 1 2 6681 2 4 2802 7 8 7419 2 5 680 7 9 2800 4 6 8953 4 7 409 3 5 2008 5 6 4066 5 7 7370 0 7 3 9 1 5 4 7 2 6 2 3 6 9 7 8 7 8 1 2
output:
7994 12860 7361 409 3211 -1 -1 7419 7419 6681
result:
wrong answer 2nd lines differ - expected: '8241', found: '12860'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%