QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#285344#676. Travelling MerchantCutesMouse12 85ms5180kbC++142.0kb2023-12-16 17:59:412023-12-16 17:59:42

Judging History

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

  • [2023-12-16 17:59:42]
  • 评测
  • 测评结果:12
  • 用时:85ms
  • 内存:5180kb
  • [2023-12-16 17:59:41]
  • 提交

answer

#include <iostream>
#define INF (1LL<<32)
#define int long long int
using namespace std;

int N, M, K;

//在a市場買b物品時的花費
int b[101][1001] = {0};
//在a市場賣b物品時的所得
int s[101][1001] = {0};
//臨邊矩陣
int w[101][101] = {0};
//在市場a買入、在市場b賣掉的最高獲利
int profit[101][101] = {0};

void floyd(int d[101][101]) {
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

bool is_legal(int profit_ratio) {
    int check[101][101] = {0};
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            check[i][j] = profit_ratio * min(w[i][j], INF) - profit[i][j];
        }
    }
    floyd(check);
    for (int i = 0; i < N; i++) {
        if (check[i][i] <= 0) return true;
    }
    return false;
}

template<class Ty, class FuncTy>
pair<Ty, Ty> bs(Ty L, Ty R, FuncTy check) {
    if (check(L) == false) return {L-1, L};
    if (check(R) == true) return {R, R+1};
    while (L + 1 < R) {
        Ty mid = L + (R - L) / 2;
        if (check(mid)) L = mid;
        else R = mid;
    }
    return {L, R};
}

signed main() {
    cin >> N >> M >> K;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < K; j++) cin >> b[i][j] >> s[i][j];
    }
    int from, to, weight;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            w[i][j] = INF;
            //profit[i][j] = 0;
        }
    }
    for (int i = 0; i < M; i++) {
        cin >> from >> to >> weight;
        w[from-1][to-1] = weight;
    }
    floyd(w);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < K; k++) {
                if (b[i][k] == -1 || s[j][k] == -1) continue;
                profit[i][j] = max(profit[i][j], s[j][k] - b[i][k]);
            }
        }
    }
    cout << bs(1LL, INF, is_legal).first;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 12
Accepted

Test #1:

score: 12
Accepted
time: 58ms
memory: 5144kb

input:

100 181 1000
553730496 158361961 892706912 178296397 743382683 297380306 641674485 99624440 917350062 18856036 844421978 187895310 648680590 312745394 560991872 402321479 712754581 166489560 776432653 57402415 554268728 511597509 861517186 541462029 843246768 457630601 923371196 521104850 557772066 ...

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 2ms
memory: 4388kb

input:

100 100 1
1 1
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 100...

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 23ms
memory: 4396kb

input:

100 100 1
1 1
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 100...

output:

9999999

result:

ok single line: '9999999'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

50 98 1
294990003 -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 481362725
-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...

output:

1968

result:

ok single line: '1968'

Test #5:

score: 0
Accepted
time: 4ms
memory: 3952kb

input:

50 146 2
159591094 -1 152896514 -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 962186931
-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 ...

output:

12512

result:

ok single line: '12512'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3900kb

input:

50 50 3
724315557 40661616 888500313 492213321 669530670 343751759
-1 349184557 -1 123681117 -1 416489184
-1 376740434 -1 524659730 -1 308601359
-1 544715761 -1 206108083 -1 241453594
-1 500022763 -1 65259007 -1 210716628
-1 32350566 -1 167450879 -1 397678219
-1 484826182 -1 132481950 -1 139031923
-...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3996kb

input:

50 50 50
891479383 484772280 972520765 460897526 852794515 220696128 675355181 162826783 595520625 317178479 928536077 41783603 637233354 48683751 939337578 12210312 835648124 328095767 884417707 439843653 604057461 198149458 682206647 375826043 628570854 479841622 973619107 171111598 901599380 4192...

output:

1200008

result:

ok single line: '1200008'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

4 4 1
1 -1
-1 2
-1 17
-1 15
1 2 1
2 3 1
3 4 1
4 1 1

output:

4

result:

ok single line: '4'

Test #9:

score: 0
Accepted
time: 4ms
memory: 3900kb

input:

50 50 1
1 1
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 1000000000
-1 10000...

output:

19999999

result:

ok single line: '19999999'

Test #10:

score: 0
Accepted
time: 4ms
memory: 4132kb

input:

50 146 10
751094001 488028533 670635071 279189552 719865752 62857436 945035157 99942140 635724731 336304928 539721394 260175851 762704228 41970290 951557180 106161633 464415091 134662977 833758012 522554183
-1 30927372 -1 281363132 -1 64696223 -1 35169633 -1 426745823 -1 235500852 -1 380932326 -1 16...

output:

20025608

result:

ok single line: '20025608'

Test #11:

score: 0
Accepted
time: 4ms
memory: 4004kb

input:

50 144 5
669304181 -1 479970956 -1 167649828 -1 470258299 -1 885426197 -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 -...

output:

65926480

result:

ok single line: '65926480'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

10 18 1
167140269 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 902165905
-1 -1
-1 -1
9 3 1
3 8 1
4 6 1
5 1 1
2 1 1
6 1 1
2 7 1
8 7 1
2 5 1
1 2 1
1 6 1
8 4 1
7 1 1
1 9 1
10 1 1
2 10 1
3 7 1
9 5 1

output:

147005127

result:

ok single line: '147005127'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3996kb

input:

50 100 50
853543611 84398909 750508785 293224633 467984755 368609270 660008525 69724893 777295826 543143283 660075741 355270173 942285924 207494807 940093193 281162609 535796018 299388697 712530736 204347888 999684888 220043146 779150015 396635929 891605908 484405769 785572566 4921986 907713030 7234...

output:

0

result:

ok single line: '0'

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 21
Accepted
time: 4ms
memory: 4132kb

input:

50 50 20
1000000000 94476 1000000000 75837 1000000000 27079 1000000000 129004 1000000000 100830 1000000000 98560 1000000000 99302 1000000000 65993 30410 1 1000000000 66183 1000000000 89148 1000000000 21236 1000000000 11935 1000000000 53895 1000000000 126490 1000000000 104741 1000000000 78615 1000000...

output:

1003

result:

ok single line: '1003'

Test #15:

score: 0
Accepted
time: 4ms
memory: 4168kb

input:

50 50 10
-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 339508586 -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...

output:

15782746

result:

ok single line: '15782746'

Test #16:

score: 0
Accepted
time: 0ms
memory: 4032kb

input:

50 50 50
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 12 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 10000 10000 -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 ...

output:

203

result:

ok single line: '203'

Test #17:

score: 0
Accepted
time: 0ms
memory: 4020kb

input:

48 48 50
-1 -1 10002 10002 -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 10 -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 ...

output:

212

result:

ok single line: '212'

Test #18:

score: 0
Accepted
time: 5ms
memory: 3976kb

input:

50 50 50
662985743 94901609 899384837 65628166 673532122 180059305 627752310 127592351 824072744 87540640 507122543 377977048 635262419 187630987 838541684 187757801 577199874 274873255 694303855 184204318 853356130 175381182 520003147 69588361 734732717 178931356 807461406 173458145 548944353 44467...

output:

24700682

result:

ok single line: '24700682'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

5 6 2
-1 7 -1 120
-1 -1 -1 152
1 -1 -1 -1
-1 15 -1 101
-1 -1 100 -1
1 2 1
2 3 1
3 1 1
1 4 1
4 5 1
5 1 1

output:

11

result:

ok single line: '11'

Test #20:

score: -21
Wrong Answer
time: 1ms
memory: 3992kb

input:

50 80 10
1000000000 37352 1000000000 17646 1000000000 70743 1000000000 72743 1000000000 92712 1000000000 101408 1000000000 87555 1000000000 93907 1000000000 29236 1000000000 76657
-1 -1 -1 -1 -1 -1 -1 -1 93712 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 -...

output:

4294967296

result:

wrong answer 1st lines differ - expected: '888', found: '4294967296'

Subtask #3:

score: 0
Wrong Answer

Test #37:

score: 33
Accepted
time: 85ms
memory: 5180kb

input:

100 243 1000
969713863 380451398 977287381 546839551 578242281 267067963 834635238 316438277 806980243 189648353 779415475 453867771 741678190 352485450 473763928 190177433 687118672 377243148 644333594 197290749 949048287 436673078 690006797 180711316 714366028 387342721 980055654 198167471 8873988...

output:

28

result:

ok single line: '28'

Test #38:

score: -33
Wrong Answer
time: 0ms
memory: 3436kb

input:

5 7 4
727218133 319808016 451811473 341827334 983666612 208956608 712124347 20325770
625539547 511168571 950094471 396282690 649119245 412489786 504515934 498965733
955685647 120970424 900386157 487638774 666900039 254430876 841869836 23162184
670731166 282497058 791738936 425566820 916482877 602671...

output:

4294967296

result:

wrong answer 1st lines differ - expected: '8', found: '4294967296'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%