QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168675#5042. Flowpooty#WA 57ms17412kbC++201.6kb2023-09-08 19:05:232023-09-08 19:05:24

Judging History

你现在查看的是最新测评结果

  • [2023-09-08 19:05:24]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:17412kb
  • [2023-09-08 19:05:23]
  • 提交

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]);
    vi excesses;
    int currentans = 0;
    int flowexcess = 0;
    for (auto vec: comps) {

        int g1 = accumulate(vec.begin(), vec.end(), 0LL);
        //cout<<g1<<"..\n";
        int mn = g1/len;
        int d1 = 0;
        int d2 = 0;
        for (auto x: vec) {
            d1 += max(0LL, mn - x);
            d2 += max(0LL, mn + 1 - x);
        }
        excesses.push_back(d2 - d1);
        flowexcess += g1%len;
        currentans += d1;
    }
    sort(excesses.begin(), excesses.end());
    REP(i, flowexcess/len) {
        currentans += excesses[i];
    }
    return currentans;

}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc = 1;
    REP(i, tc) {
        cout<<solve()<<"\n";
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3564kb

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: 3568kb

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: 30ms
memory: 17352kb

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: 3788kb

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: 3852kb

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: 3636kb

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: 30ms
memory: 10360kb

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: 57ms
memory: 17408kb

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: 50ms
memory: 17412kb

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: 45ms
memory: 12892kb

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'