QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545199 | #32. Toll | Dimash | 10 | 200ms | 42528kb | C++17 | 2.8kb | 2024-09-03 00:55:18 | 2024-09-03 00:55:18 |
Judging History
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 = 300;
// 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:
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: 10
Accepted
Test #11:
score: 10
Accepted
time: 146ms
memory: 40916kb
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:
ok 10000 lines
Test #12:
score: 10
Accepted
time: 1ms
memory: 5864kb
input:
1 10 7 10 8 9 3477 1 2 1501 4 5 2771 7 8 9928 6 7 4122 5 6 5049 3 4 5916 0 9 0 5 0 1 0 1 0 6 0 8 0 6 0 7 0 7 0 9
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
ok 10 lines
Test #13:
score: 10
Accepted
time: 1ms
memory: 5860kb
input:
2 10 12 10 3 5 6140 3 4 178 5 6 7541 4 6 7906 6 9 9146 6 8 3730 2 4 2337 0 3 4408 5 7 9855 4 7 4491 0 2 7776 1 3 5731 0 1 0 9 0 4 0 2 0 7 0 8 0 2 0 7 0 3 0 9
output:
-1 21638 4586 7776 9077 16222 7776 9077 4408 21638
result:
ok 10 lines
Test #14:
score: 10
Accepted
time: 1ms
memory: 5888kb
input:
3 10 16 10 4 7 8566 5 8 13 3 7 8339 1 4 3897 5 7 9851 1 3 4967 3 8 5413 2 4 632 0 5 2370 4 6 935 2 5 1643 8 9 8597 7 9 2072 1 5 8131 0 4 3500 4 8 7681 0 4 0 3 0 8 0 5 0 8 0 3 0 9 0 5 0 2 0 1
output:
3500 -1 2383 2370 2383 -1 10980 2370 -1 -1
result:
ok 10 lines
Test #15:
score: 10
Accepted
time: 0ms
memory: 5968kb
input:
4 10 19 10 7 9 3612 4 8 8280 6 8 3258 1 7 8936 3 7 3812 0 6 4507 2 5 9675 7 8 6874 4 9 9864 1 6 1680 2 7 521 0 5 410 5 9 9196 3 4 489 0 7 4013 1 4 3658 6 9 8929 2 6 6913 3 5 1536 0 9 0 2 0 7 0 2 0 9 0 5 0 6 0 4 0 2 0 1
output:
7625 -1 4013 -1 7625 410 4507 -1 -1 -1
result:
ok 10 lines
Test #16:
score: 10
Accepted
time: 1ms
memory: 5960kb
input:
5 10 20 10 4 9 3779 3 9 3888 0 9 6079 3 8 182 1 9 6767 0 5 4397 1 7 2299 2 9 561 4 6 2606 1 6 558 2 6 5671 3 6 6344 4 8 7895 1 5 6666 2 5 3001 3 7 7176 0 7 8399 2 7 7202 0 6 894 0 8 7928 0 7 0 1 0 4 0 1 0 4 0 9 0 8 0 8 0 3 0 3
output:
8399 -1 -1 -1 -1 6079 7928 7928 -1 -1
result:
ok 10 lines
Test #17:
score: 10
Accepted
time: 3ms
memory: 6012kb
input:
1 1000 979 10000 551 552 2582 599 600 8981 329 330 2091 628 629 1273 846 847 1835 41 42 5797 355 356 9008 317 318 3809 416 417 649 745 746 9894 414 415 2688 30 31 441 649 650 6733 544 545 1847 435 436 9919 910 911 6718 35 36 6817 180 181 7146 497 498 1875 397 398 2562 13 14 3241 780 781 4932 486 487...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 10399 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 65774 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 51355 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 10000 lines
Test #18:
score: 10
Accepted
time: 0ms
memory: 5956kb
input:
2 1000 1796 10000 76 78 5999 933 935 9 408 411 3139 85 87 3531 107 109 3006 410 413 6585 323 324 3977 80 83 5453 63 64 58 766 769 6995 722 725 4496 411 412 3840 42 44 1599 262 264 6587 767 768 4272 888 891 1238 780 783 7281 255 257 4649 654 657 1155 559 560 8536 990 993 316 550 553 625 153 154 3543 ...
output:
747927 761801 1073354 95094 527505 656599 838904 149244 805665 672064 361906 299085 1072672 1166456 1585716 33396 1631403 589304 506739 1206263 1585716 1395897 697762 141839 325861 1572390 127280 683858 1008888 1493406 740077 1105321 1119130 1255863 1543657 501043 357982 165126 413234 1112979 734259...
result:
ok 10000 lines
Test #19:
score: 10
Accepted
time: 200ms
memory: 41112kb
input:
1 50000 49949 10000 27397 27398 8216 20920 20921 2495 2502 2503 6669 46149 46150 4010 5146 5147 7650 34862 34863 8865 24806 24807 6988 30624 30625 730 19761 19762 1485 43177 43178 7263 8208 8209 3956 33605 33606 5792 49977 49978 3506 33451 33452 8667 1119 1120 492 16100 16101 7548 14076 14077 3138 3...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 10000 lines
Test #20:
score: 10
Accepted
time: 131ms
memory: 42528kb
input:
3 50000 134991 10000 42339 42342 789 649 653 7166 48089 48090 2059 12919 12923 2883 31397 31398 3325 22999 23001 3318 22941 22946 1811 34381 34384 2600 36981 36984 166 1521 1526 7429 25020 25025 8541 48161 48162 4717 7101 7104 1582 6314 6317 4097 6001 6004 8149 33505 33507 5686 18113 18116 9033 4356...
output:
9962406 5565912 27158796 19977230 5117783 23714595 29015151 31589372 17106803 23571033 29907666 32941258 27412264 4695305 28723438 18160846 12125871 10288214 1959690 25816619 15378404 32647566 6336062 26360373 29449013 6857392 6559119 11529569 612558 20608803 5392410 11961565 12665095 24543577 27204...
result:
ok 10000 lines
Test #21:
score: 10
Accepted
time: 133ms
memory: 40848kb
input:
2 50000 99996 10000 9047 9049 8723 27292 27294 5733 21911 21913 4535 37730 37733 5192 18776 18778 9572 22944 22947 9822 4122 4124 4398 49745 49747 5920 27549 27551 6394 39547 39548 8534 21852 21854 1354 6097 6099 4037 28197 28198 5556 15501 15503 6901 5971 5973 8990 20171 20173 2898 15980 15982 346 ...
output:
41452578 47693325 39216693 24717157 20413971 56455819 41606596 8753634 9652232 23974056 48627285 16584825 69087743 35204679 62812742 32597631 60673839 51072570 67201572 48779865 53173478 30425991 61587654 20155855 50423748 13503415 37674786 11740060 41040751 30252280 54589799 62157105 35833728 34546...
result:
ok 10000 lines
Test #22:
score: 10
Accepted
time: 120ms
memory: 40856kb
input:
3 50000 74995 10000 12372 12376 3080 47207 47208 4012 36430 36434 810 33844 33847 7181 31776 31779 5816 32882 32884 5475 42169 42172 9697 25381 25385 4093 15678 15683 3058 21307 21311 9804 36364 36368 8687 2842 2846 3237 45138 45141 7630 8232 8236 7005 14224 14227 7940 22701 22704 1619 176 179 8959 ...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
ok 10000 lines
Test #23:
score: 10
Accepted
time: 75ms
memory: 21120kb
input:
5 29999 149970 3000 29425 29430 3680 15083 15087 3148 26277 26280 6909 15338 15340 7706 2866 2872 9254 8721 8728 5862 23254 23255 300 22035 22040 3612 18087 18093 1112 2501 2507 2890 10021 10025 7855 500 509 3065 5145 5153 7148 19873 19879 7802 13054 13055 635 3362 3367 3161 4255 4261 3894 9683 9688...
output:
3764442 5243754 2607597 4587502 3153637 1465255 477506 5935025 847906 604392 5724020 3241888 1044645 2667506 5282342 6344412 5112955 6025208 631462 3139490 3523982 1549129 6341143 404864 5824998 1085643 967110 5422152 2136409 731732 1344487 5124188 4053402 952056 1435153 5629580 3309755 5968236 1882...
result:
ok 3000 lines
Test #24:
score: 10
Accepted
time: 52ms
memory: 20036kb
input:
3 30000 89991 3000 9485 9487 5382 21401 21402 8333 27451 27453 5928 1931 1932 5888 18397 18399 3653 27639 27644 4636 16353 16357 2935 17090 17092 2205 3686 3687 9030 19845 19850 5302 26359 26363 711 10332 10336 3082 1412 1414 3003 9993 9996 8920 3964 3968 8466 4757 4758 5732 29829 29832 8481 28856 2...
output:
8679036 4913203 17897407 296049 5217982 6295329 5620636 5621954 12409947 13401980 863253 12055917 408984 510247 14827029 13294495 3749726 6285919 4161394 4320130 8993800 3949763 1521164 12039198 9937982 17511694 14072579 5271648 9369050 5711640 8436195 2870801 13655761 18210911 7606686 5146210 17262...
result:
ok 3000 lines
Test #25:
score: 10
Accepted
time: 45ms
memory: 19592kb
input:
5 30000 74987 3000 4430 4439 5896 19900 19907 9659 23983 23987 335 16466 16470 9025 16798 16804 3246 23840 23849 2578 7799 7803 1742 821 828 114 11374 11377 7517 19468 19470 1110 22308 22313 7479 7962 7969 9649 2665 2670 4784 8625 8633 2994 14021 14029 3952 19189 19194 2119 17880 17885 1254 19926 19...
output:
9993562 1471251 1718943 2268362 4788255 7336374 9257225 12382230 3207424 9460616 2678520 11802327 8333469 422569 2358731 1461724 8387292 7670160 5698128 1973189 7117077 12808647 3302126 279375 6323374 1098709 7173531 6001901 5457548 6995160 9424952 7441771 1450424 9624815 12855129 10164200 1039267 2...
result:
ok 3000 lines
Test #26:
score: 10
Accepted
time: 53ms
memory: 19816kb
input:
5 29999 74985 3000 1552 1557 5417 21249 21251 6634 14780 14787 9613 11827 11833 6916 5436 5442 3924 858 863 1621 10596 10600 8258 0 9 3211 20196 20204 1886 7537 7543 9643 356 360 9450 19987 19994 6768 12538 12541 4814 15332 15338 5779 1624 1628 5872 23276 23283 5001 24346 24353 4538 10747 10751 5009...
output:
9924413 6582732 8766260 7064566 1276932 6532814 11895733 4501200 2010107 9328222 9933534 2798767 2296526 5816111 12796397 1083030 -1 2557134 2113449 12298523 1587371 12830025 4336227 7797271 752087 5152962 12681987 -1 2214356 8434229 2563613 5171812 13131043 1880150 4513730 -1 6940431 7831889 776742...
result:
ok 3000 lines
Subtask #3:
score: 0
Wrong Answer
Test #27:
score: 8
Accepted
time: 1ms
memory: 5876kb
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: 5964kb
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%