QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545194 | #32. Toll | Dimash | 0 | 93ms | 30060kb | C++17 | 2.7kb | 2024-09-03 00:49:27 | 2024-09-03 00:49:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 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 = 2;
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]);
}
}
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:
132581784 25180897 90096323 137505791 182756627 56626936 92687360 213071340 230587686 133760598 165611824 64778884 242205990 81064064 101519576 9635466 101928710 32361680 148988187 70570739 84559353 27969941 70881194 192597213 168605876 70339228 177355217 144544606 63764960 85559057 47845102 1259524...
result:
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 93ms
memory: 30060kb
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:
9660551 -1 -1 29677497 -1 -1 25954841 -1 29026387 -1 -1 25117089 -1 2180255 8821457 -1 17974797 -1 31676013 22691306 -1 -1 22125829 21517896 -1 -1 -1 -1 12698182 19407256 12975298 -1 -1 -1 26717226 23860276 5148244 -1 -1 14080996 9293646 -1 -1 -1 -1 -1 19509063 -1 22475995 -1 35380640 17543002 19699...
result:
wrong answer 9343rd lines differ - expected: '9500', found: '7619'
Subtask #3:
score: 0
Wrong Answer
Test #27:
score: 8
Accepted
time: 2ms
memory: 8284kb
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: 0ms
memory: 8220kb
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 4561 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%