QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168677 | #5042. Flow | pooty# | WA | 114ms | 48940kb | C++20 | 2.1kb | 2023-09-08 19:17:23 | 2023-09-08 19:17:23 |
Judging History
answer
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPL(i, j, n) for (int i = (j); i < (n); ++i)
#define sz(X) ((int)(X).size())
using namespace std;
#define int long long
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<vi> vvi;
int solve() {
int n,m;cin>>n>>m;
vvii adj(n);
REP(i, m) {
int x,y,z;cin>>x>>y>>z;x--;y--;
adj[x].push_back({y,z});
}
vvi comps;
for (auto [v,w]: adj[0]) {
vi comp;
comp.push_back(w);
int cur = v;
while (cur != n-1) {
auto [nxt, wi] = adj[cur][0];
comp.push_back(wi);
cur = nxt;
}
comps.push_back(comp);
}
int chains = sz(comps);
int len = sz(comps[0]);
vector<map<int,int>> ctarr(chains);
vi currentthres(chains);
vi currentsmaller(chains);
set<ii> excesses;
int currentans = 0;
int flowexcess = 0;
REP(i, chains) {
vi &vec = comps[i];
int g1 = accumulate(vec.begin(), vec.end(), 0LL);
//cout<<g1<<"..\n";
int mn = g1/len;
currentthres[i] = mn;
for (auto x: vec) {
ctarr[i][x]++;
if (x < mn) {
currentans += mn - x;
currentsmaller[i]++;
}
}
flowexcess += g1%len;
}
REP(i, chains) {
int tocull = ctarr[i][currentthres[i]];
currentthres[i]++;
currentsmaller[i] += tocull;
excesses.insert({currentsmaller[i], i});
}
REP(i, flowexcess/len) {
auto [hw, idx] = *excesses.begin();
excesses.erase(excesses.begin());
currentans += hw;
int tocull = ctarr[idx][currentthres[idx]];
currentthres[idx]++;
currentsmaller[idx] += tocull;
excesses.insert({currentsmaller[idx], idx});
}
return currentans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
REP(i, tc) {
cout<<solve()<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3624kb
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: 1ms
memory: 3620kb
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: 61ms
memory: 46776kb
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: 1ms
memory: 3792kb
input:
3 2 1 2 8 2 3 10
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 1ms
memory: 3640kb
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: 1ms
memory: 3852kb
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: 78ms
memory: 15672kb
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: 114ms
memory: 48940kb
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: 96ms
memory: 48300kb
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: -100
Wrong Answer
time: 67ms
memory: 31948kb
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:
14610278422273
result:
wrong answer 1st numbers differ - expected: '12535273949303', found: '14610278422273'