QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#521390 | #5042. Flow | Andyqian7 | RE | 141ms | 25152kb | C++14 | 2.0kb | 2024-08-16 09:57:06 | 2024-08-16 09:57:06 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, s, e) for (int i = s; i <= e; i++)
#define pii pair<int, int>
#define int long long
using namespace std;
const int MAX = 2e5 + 10;
struct Edge
{
int nxt, c;
};
vector<Edge> E[MAX];
vector<int> path[MAX];
int n, m;
signed main()
{
cin >> n >> m;
rep(i, 1, m)
{
int x, y, z;
cin >> x >> y >> z;
E[x].push_back({y, z});
}
int tot = 0;
rep(i, 0, (int)E[1].size() - 1)
{
path[i].push_back(E[1][i].c);
for (int j = E[1][i].nxt; j != n; j = E[j][0].nxt)
{
path[i].push_back(E[j][0].c);
}
}
rep(i, 0, (int)E[1].size() - 1)
{
for (int j : path[i])
tot += j;
sort(path[i].begin(), path[i].end());
path[i].push_back(1e9);
}
int length = path[0].size() - 1, C = tot / length;
int l = 0, r = length - 1;
while (l < r)
{
int mid = (l + r + 1) / 2;
int sum = 0;
rep(i, 0, (int)E[1].size() - 1)
{
sum += path[i][mid];
}
if (sum <= C)
{
l = mid;
}
else
{
r = mid - 1;
}
}
int sum = 0;
rep(i, 0, (int)E[1].size() - 1)
{
sum += path[i][l];
}
C -= sum;
int ans = 0;
rep(i, 0, (int)E[1].size() - 1)
{
for (int j = 0; path[i][j] <= path[i][l]; j++)
{
ans += path[i][l] - path[i][j];
}
}
vector<pii> V;
rep(i, 0, (int)E[1].size() - 1)
{
int j;
for (j = 0; path[i][j] <= path[i][l]; j++)
;
V.push_back({j, path[i][j] - path[i][j - 1]});
}
sort(V.begin(), V.end());
rep(i, 0, (int)V.size() - 1)
{
C -= V[i].second;
ans += V[i].first * V[i].second;
if (C <= 0)
{
ans += V[i].first * C;
break;
}
}
cout << ans;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13000kb
input:
4 3 1 2 1 2 3 2 3 4 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13000kb
input:
4 4 1 2 1 1 3 1 2 4 2 3 4 2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 103ms
memory: 24912kb
input:
100000 199996 1 2 0 1 3 0 1 4 0 1 5 0 1 6 0 1 7 0 1 8 0 1 9 0 1 10 0 1 11 0 1 12 0 1 13 0 1 14 0 1 15 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 21 0 1 22 0 1 23 0 1 24 0 1 25 0 1 26 0 1 27 0 1 28 0 1 29 0 1 30 0 1 31 0 1 32 0 1 33 0 1 34 0 1 35 0 1 36 0 1 37 0 1 38 0 1 39 0 1 40 0 1 41 0 1 42 0 1 43 0 ...
output:
49999000000000
result:
ok 1 number(s): "49999000000000"
Test #4:
score: 0
Accepted
time: 3ms
memory: 12944kb
input:
3 2 1 2 8 2 3 10
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 12972kb
input:
10 9 6 2 10 3 6 9 5 3 4 7 4 7 1 8 1 9 5 8 2 10 10 4 9 6 8 7 6
output:
7
result:
ok 1 number(s): "7"
Test #6:
score: 0
Accepted
time: 0ms
memory: 13004kb
input:
10 16 1 6 3 1 4 8 7 10 5 5 10 2 1 7 10 8 10 6 3 10 2 6 10 9 1 9 1 1 2 8 1 3 3 1 5 9 1 8 4 9 10 3 2 10 9 4 10 1
output:
15
result:
ok 1 number(s): "15"
Test #7:
score: 0
Accepted
time: 71ms
memory: 16772kb
input:
100000 99999 9700 37675 798072605 15495 90321 163368077 54399 92257 709210444 63319 92520 67520422 93508 30166 74547790 6947 86623 360482956 61958 55848 466736402 57810 92446 227585203 22096 13029 376961481 67744 64049 894979704 61006 19164 905021001 66772 87485 936298648 35501 71719 742844695 88521...
output:
12518855895642
result:
ok 1 number(s): "12518855895642"
Test #8:
score: 0
Accepted
time: 141ms
memory: 24952kb
input:
100000 199996 1 26663 319818544 1 13675 381416274 95884 100000 357045100 74770 100000 312492167 1 94245 199481444 1 89084 357597449 1 44869 796658525 51859 100000 301823532 1 69385 986854603 34566 100000 630859678 72982 100000 277482766 1 98659 43040144 31271 100000 711562870 48068 100000 90362013 7...
output:
16603075275851
result:
ok 1 number(s): "16603075275851"
Test #9:
score: 0
Accepted
time: 133ms
memory: 25152kb
input:
100000 199996 7045 100000 896426716 76796 100000 679041122 1 47443 300651279 62855 100000 169107035 1 91363 10524216 1 37552 297675942 1 38448 113866661 1 72793 818781339 1 50663 753284834 6288 100000 226245876 30910 100000 480172195 89323 100000 524055779 50586 100000 949012073 32228 100000 9426320...
output:
16635681185277
result:
ok 1 number(s): "16635681185277"
Test #10:
score: 0
Accepted
time: 96ms
memory: 20156kb
input:
100000 149997 14419 1561 274207885 83536 100000 39294158 67467 100000 602395267 40189 51832 642421443 10904 100000 531895322 76835 81591 801936327 1 70734 947423482 1 57891 226687027 1 39799 743379051 93543 100000 899005151 26357 23311 117493281 1 6649 314347003 18402 100000 927043195 33319 100000 2...
output:
12535273949303
result:
ok 1 number(s): "12535273949303"
Test #11:
score: 0
Accepted
time: 104ms
memory: 20408kb
input:
100000 149997 1 9231 932955576 30620 100000 719978370 1 40093 357198401 1 34631 668849404 57137 100000 558934027 1 62865 969235768 30025 100000 541428215 1 18336 62389481 40410 100000 312180730 15007 100000 553327330 9667 100000 825480993 93157 63776 570667384 1 76401 963514933 69616 100000 73988257...
output:
12472257870392
result:
ok 1 number(s): "12472257870392"
Test #12:
score: 0
Accepted
time: 75ms
memory: 16736kb
input:
100000 100000 34515 13190 977742361 20513 28489 995722642 32419 26056 811895567 59221 24444 242734607 95196 13086 873803734 96421 69037 576843698 66235 67928 81351296 60586 10244 255573158 90444 98601 901670001 12990 426 679784115 62071 36704 220174504 56259 36036 576803340 43799 68489 307286567 516...
output:
12473367661180
result:
ok 1 number(s): "12473367661180"
Test #13:
score: 0
Accepted
time: 140ms
memory: 24908kb
input:
100000 199996 1 82598 247596837 1 85534 333844371 1 41322 715308300 11915 100000 986963831 37077 100000 672455669 62494 100000 48618809 1 69123 918770198 1 90209 185230790 47558 100000 808066963 1 24763 265095626 37839 100000 361288873 1 9729 953966535 1 52304 6030834 95140 100000 465407597 32828 10...
output:
16620066384947
result:
ok 1 number(s): "16620066384947"
Test #14:
score: 0
Accepted
time: 23ms
memory: 13936kb
input:
26043 26042 6539 20396 990614068 19155 2058 7434436 10059 24942 800730799 18765 685 485063101 524 4982 691375730 3398 25045 843787823 8357 2452 332601268 25277 10484 549653995 25104 14108 407058723 14884 21596 44500491 13792 2924 268346953 23117 621 447776680 14465 12941 771783689 16777 10214 278653...
output:
3251384219123
result:
ok 1 number(s): "3251384219123"
Test #15:
score: 0
Accepted
time: 36ms
memory: 15428kb
input:
36576 54861 11583 9857 14473315 7112 8983 419177205 36283 8139 585447157 1 6993 744133035 10183 36576 450456617 1 3514 913980559 1 35298 323579337 11777 19211 6444827 32948 33245 940221490 20916 2424 198052320 30994 2642 677971055 2820 14501 717287250 1 3403 680497692 1 27853 840872357 32274 33881 3...
output:
4552532643354
result:
ok 1 number(s): "4552532643354"
Test #16:
score: 0
Accepted
time: 19ms
memory: 14300kb
input:
27645 30156 8120 13855 223767280 24803 26991 179556048 14946 17423 44100044 10701 27645 513429107 20468 21918 850123403 1 26218 491026733 5108 20209 917964013 20654 27645 499802099 18328 6312 857990458 18058 6555 909308426 1 12354 9194970 23017 23852 964708152 18722 15684 295650821 17954 18738 13475...
output:
3483710412493
result:
ok 1 number(s): "3483710412493"
Test #17:
score: 0
Accepted
time: 23ms
memory: 14340kb
input:
27932 29400 1720 20447 123059920 12502 12753 980805551 26785 16865 39771503 13959 4108 955981099 9003 8897 629957515 21311 10158 507096716 502 17375 565820327 7729 20302 221347345 11209 16311 759594739 19511 14616 528197947 4844 2524 392890658 16228 7558 431219699 24872 1845 640114626 15777 3310 206...
output:
3476819421052
result:
ok 1 number(s): "3476819421052"
Test #18:
score: 0
Accepted
time: 16ms
memory: 14020kb
input:
19001 21110 3999 14515 458837027 6806 7378 264626298 8053 13184 915972060 1282 1965 572173230 1 384 80515832 14870 4644 171238655 16183 6763 19337314 2299 11098 323912487 14593 15355 945028882 2550 2940 511536345 16908 10411 708125496 1 16176 520126900 16184 8426 201920212 1 14447 579815963 18294 28...
output:
2390066062782
result:
ok 1 number(s): "2390066062782"
Test #19:
score: 0
Accepted
time: 9ms
memory: 13432kb
input:
10070 10069 5860 5340 566505515 1554 7818 268866545 2546 8712 392437539 571 8675 178159905 9512 2738 507148888 3064 5640 875165763 2941 9367 444357059 8909 1322 580676640 804 3182 78440475 2559 5944 510519997 6465 6983 424656047 623 6393 220130911 4213 383 825661260 2512 1726 30769068 98 4399 664586...
output:
1245850499999
result:
ok 1 number(s): "1245850499999"
Test #20:
score: 0
Accepted
time: 14ms
memory: 13768kb
input:
20603 20628 19228 10978 743241901 5233 10099 726654870 11030 147 586624042 3516 15035 102004580 11331 4892 184246257 10846 13740 676985644 4416 2137 549706650 10673 2231 746986646 16306 18706 649110374 14979 11495 531395968 16714 3375 482236158 1387 7948 143138563 16260 8554 444298163 12857 4728 194...
output:
2583329335371
result:
ok 1 number(s): "2583329335371"
Test #21:
score: 0
Accepted
time: 6ms
memory: 13568kb
input:
11003 11580 7405 10109 879667451 1 1516 151493537 4270 5932 627964113 1899 1280 205082864 3119 854 311673195 4496 3413 264445735 8388 9597 570267932 5305 1459 965737320 7075 2010 484148550 6387 3841 824932571 3216 8011 947729199 2369 9449 277040969 8883 2821 129601896 31 3962 240741121 4956 5685 600...
output:
1386147620537
result:
ok 1 number(s): "1386147620537"
Test #22:
score: 0
Accepted
time: 32ms
memory: 15272kb
input:
21535 43066 12587 21535 6254045 15445 21535 784166389 1 14467 214858299 1 7843 697258161 19914 21535 613875727 6360 21535 530649309 2306 21535 147351236 1 16503 899719059 1 12427 102030294 2541 21535 557542077 4516 21535 562103070 13873 21535 688721524 1 16619 372775489 1 9238 391443526 1 5444 64881...
output:
3585206876675
result:
ok 1 number(s): "3585206876675"
Test #23:
score: 0
Accepted
time: 19ms
memory: 14060kb
input:
12604 25204 1 6097 741642929 11025 12604 639748333 1 5106 659470620 1 10882 375845504 1 4246 980108509 10831 12604 976051462 1 1466 232813177 1 10324 632597659 4753 12604 210462366 4092 12604 597348214 1 6906 675616119 1 7482 563144443 2951 12604 855959884 6747 12604 997548048 1 5154 883827097 1 56 ...
output:
2100340909518
result:
ok 1 number(s): "2100340909518"
Test #24:
score: 0
Accepted
time: 0ms
memory: 13088kb
input:
2645 3524 1 1259 636059047 1596 592 46090283 1199 1221 77891981 1098 2645 402750837 1 1961 486563476 1210 2645 50730864 114 2645 130640398 1 2197 919473188 417 2030 387878126 1 1181 472113798 396 2297 821827540 2257 2514 582429301 2602 2645 853799599 1713 1992 533905799 155 2554 404473818 2180 2379 ...
output:
346904880130
result:
ok 1 number(s): "346904880130"
Test #25:
score: 0
Accepted
time: 7ms
memory: 13732kb
input:
3960 7916 832 3960 599894994 1 1323 120886915 1 2448 793675349 1 3490 221077741 1 992 897326867 1 2485 969823271 3431 3960 553814317 3806 3960 659272664 3626 3960 447714167 1 3808 951339360 1 596 353267951 1 2474 19081116 3717 3960 765783959 1 1280 198220013 1 3179 836270439 1 413 363557702 1 2880 5...
output:
653947493665
result:
ok 1 number(s): "653947493665"
Test #26:
score: 0
Accepted
time: 6ms
memory: 13264kb
input:
4247 4246 2213 2539 643648615 1213 1293 532642289 4087 422 745299079 1231 1693 726574371 2966 310 518196348 768 2885 863378188 5 2095 134574290 271 414 836392544 3623 1778 770190304 3583 1704 291141985 869 983 422611807 2155 1979 659672403 3346 306 129596176 1995 3510 349997750 2364 3993 238797408 5...
output:
532710689593
result:
ok 1 number(s): "532710689593"
Test #27:
score: 0
Accepted
time: 89ms
memory: 19312kb
input:
95315 127084 42601 33316 143233626 47072 64659 97117642 51513 17527 231461232 39180 95315 846947826 76176 38049 133681393 20006 39005 238536586 1 10943 246291192 32959 95315 639975733 20089 23789 821406090 76910 95315 177899680 72883 63749 337074074 42288 86693 343344424 1 11102 610081559 1 4821 518...
output:
12785143229477
result:
ok 1 number(s): "12785143229477"
Test #28:
score: 0
Accepted
time: 0ms
memory: 13204kb
input:
2 1 1 2 0
output:
0
result:
ok 1 number(s): "0"
Test #29:
score: -100
Runtime Error
input:
2 1 1 2 1000000000