QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75235 | #3871. Voting Cities | hassybirobiro | 10 | 383ms | 199496kb | C++17 | 4.1kb | 2023-02-04 17:00:16 | 2023-02-04 17:00:18 |
Judging History
answer
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<long>;
using vvl = vector<vl>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vstr = vector<string>;
constexpr ll INF_LL=1e17;
constexpr int INF_I=1LL<<30;
constexpr ll inf = 1e12 + 7;
#define rep(i,n) for(int i=0; i<((int)(n)); i++)
#define reps(i,n) for(int i=1; i<=((int)(n)); i++)
#define vector_cin(x) for(auto &n : (x)) cin >> n
#define ALL(x) (x).begin(), (x).end()
#define YesNo(x) ((x) ? "Yes": "No")
#define pb emplace_back
#define to_lower(S) transform(ALL((S)), (S).begin(), ::tolower)
#define to_upper(S) transform(ALL((S)), (S).begin(), ::toupper)
template <typename T>
bool chmax(T &a, const T& b) {if (a < b){a = b;return true;}return false;}
template <typename T>
bool chmin(T &a, const T& b) {if (a > b){a = b;return true;}return false;}
ll ceilint(ll x, ll y) {return (x + y - 1) / y;}
void Main();
int main() {std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);std::cout << std::fixed << std::setprecision(15);Main();return 0;}
//-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
struct edge{
ll to, cost;
edge(ll t, ll c) : to(t), cost(c) {};
};
using Graph = vector<vector<edge>>;
vll dijikstra(Graph& G, ll s, ll N, vll& prev) {
vll dist(N, INF_LL);
dist[s] = 0;
priority_queue<pll, vpll, greater<pll>> Q;
Q.push({dist[s], s});
while (!Q.empty()) {
ll v = Q.top().second;
ll c = Q.top().first;
Q.pop();
if (dist[v] < c) continue;
for (auto& e : G[v]) {
if (dist[e.to] > e.cost + c) {
dist[e.to] = e.cost + c;
prev[e.to] = v;
Q.push({dist[e.to], e.to});
}
}
}
return dist;
}
vll getpath(vll& prev, ll g) {
vll path;
for (int cur = g; cur != -1; cur = prev[cur])
path.pb(cur);
reverse(ALL(path));
return path;
}
void Main () {
ll N, E, K;
cin >> N >> E >> K;
Graph G(N);
vll T(K);
vvll edge_cost(N, vll(N, -1));
vector_cin(T);
rep(i, E) {
ll U, V, C;
cin >> U >> V >> C;
edge_cost[U][V] = C;
G[U].pb(edge(V, C));
}
ll Q;
cin >> Q;
if (Q == 1 && K == 1) {
ll S;
cin >> S;
vll prev(N, -1);
auto d = dijikstra(G, S, N, prev);
cout << d[T[0]] << endl;
}
while (Q--) {
ll S;
cin >> S;
vll P(5);
rep(i, 5) cin >> P[i];
ll ans = INF_LL;
vll d, path, prev(N, -1);
d = dijikstra(G, S, N, prev);
for (auto& t : T) {
if (d[t] == INF_LL)
continue;
vll costs;
path = getpath(prev, t);
rep(i, path.size()) {
if (i > 0) {
costs.pb(edge_cost[path[i - 1]][path[i]]);
}
}
sort(ALL(costs), greater<ll>());
for (int bit = 0; bit < (1LL << 5); bit++) {
vll V;
rep(i, 5) if (bit & (1LL << i)) V.pb(i);
reverse(ALL(V));
ll dist = d[t];
ll j = 0;
rep(i, V.size()) {
if (P[V[i]] == -1) continue;
if (P[V[i]] > (costs[j] / 10) * (V[i] + 1)) {
dist = INF_LL;
break;
}
dist += P[V[i]];
dist -= (costs[j] / 10) * (V[i] + 1);
j++;
if (j >= costs.size()) break;
}
chmin(ans, dist);
}
}
if (ans != INF_LL)
cout << ans << endl;
else
cout << -1 << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
5000 10000 1 4683 0 715 579327370 0 954 664830350 0 2453 244225980 0 2918 399241150 0 3929 982683290 1 4944 723915200 2 3725 390369490 3 1370 230814450 3 3348 750421430 3 3408 503334040 4 252 852709300 4 989 474431070 4 1013 466847840 4 4956 152207550 5 4162 271201150 6 3335 991911830 6 3596 4382854...
output:
7570531610 -1
result:
Subtask #2:
score: 5
Accepted
Test #6:
score: 5
Accepted
time: 60ms
memory: 199404kb
input:
5000 10000 1 939 0 1074 697931020 0 4334 347738890 1 2400 681303040 2 1685 896587820 2 2368 928896100 2 3133 12276450 2 3258 765661210 4 3606 993201320 5 1081 613705100 5 2339 700470170 5 2625 209307440 5 2832 129029550 7 1517 251821020 7 1751 713428320 7 2308 951691550 7 3980 498317440 7 4014 78197...
output:
5627552460 -1 4246029940 3761657420 4380835410 2491074640 3803606150 4373173360 -1 -1 2801457640 -1 4795371840 4240270840 -1 -1 -1 4178646650 1904132330 4723617640 -1 3681994990 4524064110 6370263130 2936159730 4375108180 6982682750 6477915010 4681205940 -1 3755439560 -1 6819403420 3673261770 -1 504...
result:
ok 100 lines
Test #7:
score: 0
Accepted
time: 75ms
memory: 199364kb
input:
5000 4999 1 1600 0 4814 896397660 1 4984 739406180 2 694 114517340 3 4309 218471300 4 920 590985330 5 2719 754542380 6 2504 137382510 7 1035 499505610 8 1496 125459930 9 2835 281015760 10 2884 593613550 11 4299 563512780 12 1641 78196580 13 4063 437582110 14 4531 161182440 15 1985 146282870 16 1542 ...
output:
2482347025410 2413549249250 1163267123140 193707105420 1303191463070 1150457808750 416481342360 958052897780 1627382495400 2213481766090 63918924520 1385980498700 1787190634400 385286330050 694780572660 536069307270 665015464460 2050578445880 2417231990400 696189478770 11411899680 296514744410 75144...
result:
ok 100 lines
Test #8:
score: 0
Accepted
time: 84ms
memory: 199428kb
input:
5000 10000 1 499 0 1 694980180 0 2433 28823070 1 2 728686200 1 86 619222880 2 3 26992400 2 4 839612680 2 1898 635010730 4 5 377517310 4 6 749940480 5 2667 791214220 6 7 745281280 6 8 400320590 7 1260 918251840 7 3221 257682180 8 9 628377120 9 10 13654560 10 11 855598110 10 3389 687839800 10 3848 208...
output:
6545145780 6320543620 5558635220 7832193970 6015073740 5715376930 4015418390 3535383550 -1 5146644790 -1 7948033760 -1 -1 6960357490 4380884330 -1 4853943790 5787118910 5175104430 5028667730 -1 -1 5076114990 6264416340 5073783270 3961639500 7416222680 6459744650 7017837430 5371935030 5542488450 7137...
result:
ok 100 lines
Test #9:
score: 0
Accepted
time: 1ms
memory: 3384kb
input:
5 6 1 1 0 3 578761210 1 2 507284400 2 3 249485200 3 2 652750640 4 0 112590950 4 1 438010780 2 0 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1
output:
-1 -1
result:
ok 2 lines
Test #10:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
3 3 1 1 1 0 567487650 1 2 917405800 2 1 249016270 3 1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1
output:
0 -1 249016270
result:
ok 3 lines
Subtask #3:
score: 5
Accepted
Test #11:
score: 5
Accepted
time: 383ms
memory: 199396kb
input:
5000 10000 2000 366 1016 3277 5 3742 3640 2511 1725 2168 2349 1037 4972 2930 4374 3504 1098 3439 3970 1952 3474 2664 2097 1751 3679 3155 3266 2070 2016 338 1273 2648 4398 3694 2045 3524 1027 839 1898 1795 1192 2975 1756 4707 1548 4984 1891 2364 123 3181 1096 2970 3264 1628 1295 4852 829 4940 2251 37...
output:
0 0 -1 524672860 0 0 0 206839450 707709240 0 738220490 0 590711250 638089240 0 0 0 0 2259893470 0 0 1425582250 417331380 1369108520 848243380 568654300 -1 31220760 101654610 0 68502140 0 1923846430 -1 1073048140 0 895045250 0 207461590 -1 562502090 867633840 0 44530950 -1 0 0 0 0 614867560 130393210...
result:
ok 100 lines
Test #12:
score: 0
Accepted
time: 59ms
memory: 199392kb
input:
5000 4999 5 612 531 1968 410 2782 0 2103 349281350 1 2480 594374500 2 2033 402172500 3 403 80637270 4 1816 160451980 5 639 846953920 6 2664 977129160 7 521 422049390 8 381 804390200 9 4823 279895120 10 4437 160159660 11 111 644269260 12 2918 579533860 13 3020 277966440 14 3067 626653710 15 3418 6878...
output:
88817191850 1183150862130 209485420890 313903092290 305571745150 192504729570 71621285160 929980930730 299152884440 147595181610 1189655433660 1023128543510 239735056920 136198489290 665815290630 124175311160 212188941690 158535471660 124411315210 189647282680 196753410780 137772024310 178918749330 ...
result:
ok 100 lines
Test #13:
score: 0
Accepted
time: 95ms
memory: 199496kb
input:
5000 10000 10 1390 2211 1281 4355 4632 1243 4356 1010 2391 2700 0 1 133262380 1 2 727699550 1 705 534362220 1 4986 70479650 2 3 907226330 2 3460 709286650 3 4 175466540 3 6 948045550 3 7 487883480 4 5 943367740 4 3162 946618820 4 4917 187658450 7 8 790383730 7 15 357484820 7 1516 158800830 8 9 34017...
output:
3930294140 2759540890 2741810620 3922456530 2662043850 3036944090 3576962770 2751271190 2064675880 3217717780 3143225060 3445699300 -1 2473253080 2347081530 3377890460 3043574850 -1 3483450210 2387724730 4170287160 4990061730 2949093580 3991840440 1974073420 3260190340 -1 1737747670 0 3046500000 278...
result:
ok 100 lines
Test #14:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
5 6 2 1 0 1 3 764266000 2 1 660773340 2 4 128055370 3 0 591098210 3 2 555395050 4 3 788956120 4 0 -1 -1 -1 -1 -1 4 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1
output:
0 1380054330 0 660773340
result:
ok 4 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
3 3 3 0 1 2 0 2 232764240 2 0 150858370 2 1 132459350 3 1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1
output:
0 0 0
result:
ok 3 lines
Subtask #4:
score: 0
Runtime Error
Test #16:
score: 0
Runtime Error
input:
5000 10000 1 4577 0 248 57534230 0 3020 827662530 0 3190 138424730 1 3154 752916230 4 1256 398736840 5 4116 833556610 5 4127 547494700 6 396 793865570 6 1661 388141660 7 4581 595148940 8 3768 724151300 9 1367 840320860 9 1656 391917460 10 3210 806346090 10 3356 767016610 10 3367 272248610 12 1145 72...
output:
100000000000000000
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Runtime Error
Test #22:
score: 0
Runtime Error
input:
5000 10000 200 1044 1225 1941 2497 4667 2566 3603 92 2261 1826 770 4780 127 4386 1948 2156 1504 4511 3119 4006 4473 389 3469 2670 3989 3092 55 670 4525 4965 1038 375 419 2599 4912 3665 4799 2997 4759 1660 1136 2308 1707 4249 3246 625 3378 52 734 4317 4958 3355 869 3361 2010 2300 2809 2635 2241 3441 ...
output:
-1 2711183020 697856260 1516782260 2354919910 -1 480464090 -1 2697573650 -1 1124944640 1861504690 -1 -1 741307190 -1 -1 976285550 2852046420 1719694410 2990735250 2873388140 1662807060 2174636268 1457722880
result:
Subtask #7:
score: 0
Runtime Error
Test #26:
score: 0
Runtime Error
input:
100 1000 10 98 30 76 47 68 72 37 62 38 78 0 40 955510110 0 58 380472040 0 67 471726660 0 75 21910230 0 76 203779460 0 79 619337400 0 92 789108960 0 95 850838250 1 7 708430 1 8 800979960 1 24 529606990 1 25 822365030 1 40 803087030 1 75 339182160 1 79 841073850 1 86 249876300 1 92 93708160 2 6 653731...
output:
410099610 386216320
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
0%