QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425847#6113. Window ArrangementHKOI0#AC ✓2157ms6324kbC++204.7kb2024-05-30 17:36:192024-05-30 17:36:20

Judging History

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

  • [2024-05-30 17:36:20]
  • 评测
  • 测评结果:AC
  • 用时:2157ms
  • 内存:6324kb
  • [2024-05-30 17:36:19]
  • 提交

answer

#include <bits/stdc++.h>
#include <bits/extc++.h>
#define int long long
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = numeric_limits<ll>::max() / 16;

struct MCMF {
    struct edge {
        int from, to, rev;
        ll cap, cost, flow;
    };
    int N;
    vector<vector<edge>> ed;
    vi seen;
    vector<ll> dist, pi;
    vector<edge*> par;

    MCMF(int N): N(N), ed(N), seen(N), dist(N), pi(N), par(N) {}

    void addEdge(int from, int to, ll cap, ll cost) {
        #ifdef LOCAL
            cout << "EDGE " << from << ' ' << to << ' ' << cap << ' ' << cost << endl;
        #endif
        if (from == to) return;
        ed[from].push_back(edge{ from,to,sz(ed[to]),cap,cost,0 });
        ed[to].push_back(edge{ to,from,sz(ed[from])-1,0,-cost,0 });
    }

    void path(int s) {
        fill(all(seen), 0);
        fill(all(dist), INF);
        dist[s] = 0; ll di;

        __gnu_pbds::priority_queue<pair<ll, int>> q;   
        vector<decltype(q)::point_iterator> its(N);
        q.push({ 0, s });

        while (!q.empty()) {
            s = q.top().second; q.pop();
            seen[s] = 1; di = dist[s] + pi[s];
            for (edge& e : ed[s]) if (!seen[e.to]) {
                ll val = di - pi[e.to] + e.cost;
                if (e.cap - e.flow > 0 && val < dist[e.to]) {
                    dist[e.to] = val; assert(val >= 0);
                    par[e.to] = &e;
                    if (its[e.to] == q.end())
                        its[e.to] = q.push({ -dist[e.to], e.to });
                    else
                        q.modify(its[e.to], { -dist[e.to], e.to });
                }
            }
        }
        for (int i = 0; i < N; i++) {
            pi[i] = min(pi[i] + dist[i], INF);
        }
    }

    pair<ll, ll> maxflow(int s, int t) {
        ll totflow = 0, totcost = 0;
        while (path(s), seen[t]) {

            ll fl = INF;
            for (edge* x = par[t]; x; x = par[x->from])
                fl = min(fl, x->cap - x->flow);

            totflow += fl;
            for (edge* x = par[t]; x; x = par[x->from]) {
                x->flow += fl;
                ed[x->to][x->rev].flow -= fl;
            }
        }
        for (int i = 0; i < N; i++) for (edge& e : ed[i]) totcost += e.cost * e.flow;
        // cout << totflow << ' ' << totcost / 2 << endl;
        return {totflow, totcost/2};
    }

    void setpi(int s) {
        fill(all(pi), INF); pi[s] = 0;
        int it = N, ch = 1; ll v;
        while (ch-- && it--)
            for (int i = 0; i < N; i++) if (pi[i] != INF)
                for (edge& e : ed[i]) if (e.cap)
                    if ((v = pi[i] + e.cost) < pi[e.to])
                        pi[e.to] = v, ch = 1;
        assert(it >= 0);
    }
};

void solve() {
    int n,m; cin >> n >> m;
    vector<vector<int>> p(n, vector<int>(m, 0)), w = p;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> p[i][j];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> w[i][j];

    const int SRC = 3 * n * m;
    const int SINK = 3 * n * m + 1;
    const int HORI_BASE = n * m;
    const int VERT_BASE = 2 * n * m;
    MCMF mcmf(3 * n * m + 2);

    // ROOM
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            mcmf.addEdge(SRC, i * m + j, 4 - w[i][j], 0);

    ll totalDiscomfort = 0;

    // HORI
    for (int i = 0; i < n; i++)
        for (int j = 0; j + 1 < m; j++) {
            const int room1 = i * m + j;
            const int room2 = i * m + (j + 1);
            const int edge = HORI_BASE + room1;

            totalDiscomfort += p[i][j] * p[i][j + 1];

            mcmf.addEdge(room1, edge, 1, 0);
            mcmf.addEdge(room2, edge, 1, 0);
            mcmf.addEdge(edge, SINK, 1, -p[i][j] * p[i][j + 1]);
        }

    // VERT
    for (int i = 0; i + 1 < n; i++)
        for (int j = 0; j < m; j++) {
            const int room1 = i * m + j;
            const int room2 = (i + 1) * m + j;
            const int edge = VERT_BASE + room1;

            totalDiscomfort += p[i][j] * p[i + 1][j];

            mcmf.addEdge(room1, edge, 1, 0);
            mcmf.addEdge(room2, edge, 1, 0);
            mcmf.addEdge(edge, SINK, 1, -p[i][j] * p[i + 1][j]);
        }

    mcmf.setpi(SRC);
    const ll maxcost = -mcmf.maxflow(SRC, SINK).second;
    // cout << totalDiscomfort << ' ' << maxcost << '\n';
    cout << totalDiscomfort - maxcost << '\n';
}

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    // cin >> T;
    while (T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

input:

4 3
1 7 10
7 2 8
7 9 10
4 6 4
3 3 3
3 2 4
4 3 4
2 2 3

output:

178

result:

ok 1 number(s): "178"

Test #2:

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

input:

4 3
2 2 9
9 8 4
8 4 5
7 5 2
0 1 0
1 0 1
0 0 1
0 1 0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 28ms
memory: 4316kb

input:

20 20
755 344 600 54 516 407 657 429 565 185 90 323 449 464 872 138 404 500 196 111
666 191 824 98 505 538 949 801 266 861 984 957 396 851 496 147 225 451 874 380
536 200 581 397 305 514 351 416 228 763 566 442 618 131 527 651 954 757 226 129
286 608 819 477 891 22 19 747 565 704 198 703 736 8 835 1...

output:

14347279

result:

ok 1 number(s): "14347279"

Test #4:

score: 0
Accepted
time: 25ms
memory: 4160kb

input:

20 20
883 996 857 428 770 375 536 417 721 664 530 67 347 193 683 55 126 251 918 160
415 776 141 481 362 746 171 662 682 27 506 739 391 283 605 747 955 822 408 490
124 123 362 556 302 894 162 660 846 126 487 389 607 952 719 885 545 378 273 741
797 417 859 458 922 875 804 871 60 542 43 785 751 519 710...

output:

17832787

result:

ok 1 number(s): "17832787"

Test #5:

score: 0
Accepted
time: 30ms
memory: 4260kb

input:

20 20
12 841 115 905 831 152 815 405 876 550 673 811 141 138 710 972 745 513 936 400
355 554 651 160 219 658 688 419 699 897 925 305 978 420 418 451 685 897 645 705
225 533 655 10 491 681 974 904 568 889 305 737 997 772 423 119 432 703 424 545
204 34 194 840 954 241 589 291 659 676 400 571 470 735 4...

output:

10140249

result:

ok 1 number(s): "10140249"

Test #6:

score: 0
Accepted
time: 177ms
memory: 4668kb

input:

30 30
797 774 295 888 552 163 89 965 38 658 757 17 679 751 765 379 981 930 470 284 953 287 129 763 332 975 658 131 71 469
628 464 611 554 436 790 498 346 226 538 108 781 747 246 219 39 481 241 736 136 929 949 939 276 948 960 351 611 327 147
19 290 259 790 418 305 325 634 12 940 359 61 939 794 989 48...

output:

24175937

result:

ok 1 number(s): "24175937"

Test #7:

score: 0
Accepted
time: 176ms
memory: 4956kb

input:

30 30
925 618 41 366 101 428 72 953 193 136 197 760 577 992 576 296 896 488 192 333 597 361 638 147 189 695 880 992 383 340
855 247 199 987 545 390 227 421 463 944 209 895 528 893 215 418 101 485 354 602 43 705 224 904 844 898 237 232 886 655
426 396 298 364 449 967 110 758 803 482 908 143 954 602 8...

output:

36345958

result:

ok 1 number(s): "36345958"

Test #8:

score: 0
Accepted
time: 171ms
memory: 4920kb

input:

30 30
349 463 594 739 355 204 951 941 53 22 444 504 667 425 603 405 322 942 210 574 346 947 147 530 750 904 101 557 503 210
81 517 194 419 653 798 661 984 997 863 502 114 821 347 404 206 208 25 268 557 964 757 317 724 36 132 828 853 37 972
937 717 633 346 184 524 791 585 402 616 560 634 969 114 636 ...

output:

31921917

result:

ok 1 number(s): "31921917"

Test #9:

score: 0
Accepted
time: 170ms
memory: 4664kb

input:

30 30
773 603 852 217 416 981 231 225 912 205 588 544 758 962 222 322 237 500 932 518 94 428 952 105 311 112 618 905 816 376
499 891 589 555 762 398 687 59 938 270 603 228 602 506 593 481 724 565 694 728 78 1000 306 249 636 663 611 666 84 776
345 630 672 623 408 889 280 5 193 942 109 524 792 521 511...

output:

26614264

result:

ok 1 number(s): "26614264"

Test #10:

score: 0
Accepted
time: 95ms
memory: 4576kb

input:

30 30
336 905 393 891 816 387 961 566 524 281 843 444 349 981 28 136 307 622 626 5 629 895 178 573 642 966 218 403 307 677
536 675 854 13 321 77 285 966 611 597 21 24 708 662 592 486 784 554 491 526 887 955 32 370 996 382 221 577 783 515
364 974 684 238 489 576 786 705 855 57 229 256 515 120 685 91 ...

output:

154020136

result:

ok 1 number(s): "154020136"

Test #11:

score: 0
Accepted
time: 98ms
memory: 4928kb

input:

30 30
464 45 139 369 69 460 648 554 383 463 579 187 736 414 543 757 29 76 348 757 377 376 983 445 203 878 735 264 915 548
250 945 441 149 430 381 503 41 144 4 610 435 489 116 780 570 891 798 109 992 296 711 614 894 892 128 108 902 638 23
67 784 723 220 712 238 763 829 646 191 74 42 530 631 264 521 9...

output:

127330425

result:

ok 1 number(s): "127330425"

Test #12:

score: 0
Accepted
time: 88ms
memory: 4700kb

input:

30 30
888 593 397 39 835 428 632 246 539 645 723 931 826 951 866 674 943 634 70 998 126 154 300 828 764 86 957 613 36 714
476 24 732 877 539 85 936 116 86 115 414 357 269 571 777 653 407 338 831 651 114 955 411 10 892 363 699 523 389 827
578 697 58 498 744 795 548 248 949 29 431 124 545 143 140 951 ...

output:

144503495

result:

ok 1 number(s): "144503495"

Test #13:

score: 0
Accepted
time: 99ms
memory: 4672kb

input:

30 30
16 734 142 220 89 909 103 530 694 827 162 675 620 384 381 783 370 385 88 239 874 740 514 507 621 102 178 178 348 584
406 294 831 14 544 685 666 191 323 329 707 768 562 729 966 441 514 582 449 118 228 7 992 343 492 597 482 144 540 440
282 18 97 776 479 160 37 76 740 163 276 615 561 551 911 86 8...

output:

133057161

result:

ok 1 number(s): "133057161"

Test #14:

score: 0
Accepted
time: 82ms
memory: 4576kb

input:

30 30
756 758 410 391 362 933 81 834 557 688 707 327 424 206 531 271 793 985 337 425 289 33 505 309 183 193 811 159 269 641
788 482 954 122 524 522 702 421 527 409 705 997 652 915 908 48 889 353 934 746 852 394 728 673 939 262 138 874 438 137
4 891 439 710 325 575 705 9 656 365 982 548 754 481 768 4...

output:

174981485

result:

ok 1 number(s): "174981485"

Test #15:

score: 0
Accepted
time: 76ms
memory: 4920kb

input:

30 30
180 898 155 869 616 6 65 822 713 871 851 366 811 935 342 893 411 543 763 178 742 811 822 884 40 402 736 724 94 807
15 856 541 259 337 930 432 392 764 327 805 407 433 369 905 835 996 597 552 108 670 638 13 302 539 496 728 495 293 941
411 508 479 692 549 236 490 941 959 499 827 142 769 697 51 92...

output:

165187617

result:

ok 1 number(s): "165187617"

Test #16:

score: 0
Accepted
time: 82ms
memory: 4628kb

input:

30 30
604 743 413 50 973 975 944 810 572 349 586 814 901 176 369 810 134 294 781 419 682 589 331 563 601 610 254 73 702 677
433 831 832 691 150 338 161 763 2 734 802 522 22 824 797 919 512 137 466 871 80 690 811 122 731 434 615 116 636 258
922 317 518 970 284 898 171 65 46 825 184 928 784 209 118 63...

output:

189511101

result:

ok 1 number(s): "189511101"

Test #17:

score: 0
Accepted
time: 100ms
memory: 4628kb

input:

30 30
732 291 967 528 227 48 223 798 728 235 538 662 695 906 180 727 48 556 799 363 431 175 841 946 650 34 475 638 14 548
659 909 227 827 450 938 891 838 239 845 391 740 507 982 986 707 619 677 892 530 193 741 392 454 923 669 502 737 491 62
330 230 853 248 315 263 956 484 645 663 29 11 503 720 994 7...

output:

146279509

result:

ok 1 number(s): "146279509"

Test #18:

score: 0
Accepted
time: 277ms
memory: 4864kb

input:

50 20
7 6 1 3 2 6 6 4 7 7 4 1 8 4 1 7 1 4 9 5
5 4 3 10 6 5 1 10 4 1 6 5 8 6 2 7 6 5 3 5
4 3 4 10 4 7 7 8 6 6 4 7 9 6 3 2 5 7 10 1
6 9 5 4 3 8 6 5 10 7 3 10 10 7 9 8 3 5 10 6
3 5 10 9 8 4 3 3 10 6 1 1 9 8 4 9 4 7 6 3
2 8 8 4 5 3 6 7 6 9 4 1 8 7 9 3 5 6 10 8
3 9 3 1 3 4 8 3 5 4 9 4 3 5 7 9 10 4 1 1
4 ...

output:

5096

result:

ok 1 number(s): "5096"

Test #19:

score: 0
Accepted
time: 1639ms
memory: 5940kb

input:

50 45
7 9 9 1 6 9 1 4 5 8 5 9 9 2 7 10 3 9 3 4 10 2 7 10 4 2 4 7 10 10 8 4 7 4 6 10 8 7 8 9 9 8 4 1 4
6 7 5 6 10 3 9 9 10 4 3 8 3 5 1 9 2 3 10 3 4 8 6 4 7 6 6 2 5 2 10 2 4 7 3 5 2 3 9 6 6 1 7 7 3
3 1 6 6 6 3 3 9 6 3 6 1 8 6 2 4 3 6 4 2 4 3 8 3 3 8 2 2 4 2 2 2 2 4 1 3 10 1 5 8 3 3 1 8 6
2 5 9 5 3 8 5...

output:

10959

result:

ok 1 number(s): "10959"

Test #20:

score: 0
Accepted
time: 1683ms
memory: 5968kb

input:

45 50
10 10 8 7 1 1 10 10 10 8 7 9 1 5 4 7 9 10 7 10 4 4 5 10 9 4 9 9 2 7 6 8 2 5 3 2 2 7 9 3 5 4 9 3 4 1 2 7 6 9
9 1 1 6 3 9 3 10 7 3 2 7 9 4 3 9 3 1 10 3 6 10 2 9 3 5 4 5 4 7 6 5 2 2 8 4 10 2 8 1 1 5 9 9 4 6 5 1 6 6
10 7 2 1 5 7 4 9 7 5 10 5 3 6 8 1 9 8 5 4 2 8 6 7 10 7 3 9 5 2 3 4 9 9 2 1 7 8 6 2...

output:

10532

result:

ok 1 number(s): "10532"

Test #21:

score: 0
Accepted
time: 2121ms
memory: 6288kb

input:

50 50
2 4 5 2 9 8 6 10 2 3 6 8 7 2 5 3 4 5 5 9 10 5 3 9 2 5 9 3 6 1 6 1 10 9 4 5 5 5 6 4 4 9 5 5 7 9 2 9 3 6
10 4 10 8 8 6 5 6 5 10 10 5 6 1 10 9 2 4 3 1 2 7 1 8 3 10 1 7 6 4 6 8 7 3 5 8 7 4 5 1 10 10 7 5 9 8 3 7 10 7
3 2 10 6 4 9 3 5 4 1 6 7 2 8 10 9 3 10 7 9 9 4 7 9 3 9 2 5 1 3 3 5 9 4 9 9 5 4 7 9...

output:

11611

result:

ok 1 number(s): "11611"

Test #22:

score: 0
Accepted
time: 2122ms
memory: 6212kb

input:

50 50
2 8 8 7 9 1 5 2 1 1 4 5 7 9 4 10 6 3 1 10 8 9 2 2 9 4 6 4 9 1 2 1 7 5 9 9 10 10 7 7 5 2 4 3 4 7 8 3 7 9
7 8 4 8 10 6 6 7 2 4 1 10 1 9 3 4 7 8 5 5 1 7 6 2 10 4 2 10 9 10 9 8 3 1 8 2 9 1 5 10 8 10 9 10 8 6 1 4 4 3
2 9 1 9 6 1 7 10 9 2 3 1 4 9 2 10 6 10 5 5 5 9 5 3 7 3 6 1 8 9 7 1 7 1 9 6 10 5 10...

output:

11341

result:

ok 1 number(s): "11341"

Test #23:

score: 0
Accepted
time: 2157ms
memory: 6228kb

input:

50 50
10 8 4 9 10 10 4 6 1 3 7 9 7 2 5 9 1 7 9 7 9 4 1 2 10 10 7 1 9 8 4 10 8 8 8 3 4 1 5 8 4 2 5 8 2 10 5 3 1 2
1 4 9 8 6 4 5 10 1 7 8 1 6 7 9 9 6 9 6 4 3 10 3 3 10 4 2 7 4 7 3 3 9 5 3 4 1 1 6 6 8 3 10 5 7 1 9 5 6 4
5 9 2 4 1 3 8 3 5 4 9 10 6 8 6 5 8 3 2 1 10 5 6 3 4 4 6 3 6 4 9 6 8 10 8 6 10 7 1 3...

output:

9600

result:

ok 1 number(s): "9600"

Test #24:

score: 0
Accepted
time: 2156ms
memory: 6316kb

input:

50 50
8 1 2 7 4 7 8 8 6 9 7 9 9 3 2 10 7 5 7 8 1 2 5 9 1 2 3 2 8 8 2 10 5 4 1 3 10 5 2 2 9 7 10 2 9 4 1 7 7 5
5 2 4 7 6 9 2 5 3 5 2 6 2 7 10 7 3 9 5 8 2 6 8 9 5 5 8 4 7 1 4 9 6 9 8 4 5 4 6 5 8 1 7 2 2 1 5 7 10 6
2 7 5 7 5 9 3 10 10 5 6 5 8 8 10 6 7 5 10 9 5 4 8 7 4 8 9 10 10 6 7 8 10 9 4 3 1 4 10 1 ...

output:

9049

result:

ok 1 number(s): "9049"

Test #25:

score: 0
Accepted
time: 969ms
memory: 6196kb

input:

50 50
1 5 2 9 6 4 6 7 7 7 6 6 4 5 6 8 7 2 1 10 3 9 9 5 4 5 10 9 6 10 2 1 7 7 10 2 5 4 3 9 5 3 6 6 1 9 4 5 3 8
6 5 6 4 4 6 4 9 8 6 6 3 7 1 5 3 3 6 1 10 2 3 7 6 9 4 3 1 5 6 10 9 5 4 2 6 6 8 7 10 2 4 6 9 10 4 4 7 10 6
2 4 7 7 9 4 10 9 6 6 5 2 7 5 5 8 8 3 1 10 7 7 1 5 10 8 3 1 4 6 9 2 9 10 8 7 3 5 8 1 1...

output:

55739

result:

ok 1 number(s): "55739"

Test #26:

score: 0
Accepted
time: 1024ms
memory: 6268kb

input:

50 50
9 10 6 9 9 3 10 5 2 9 5 10 5 8 5 5 9 8 3 1 2 7 7 5 5 3 1 8 4 10 10 1 4 9 7 10 4 9 7 10 8 3 7 5 10 7 9 5 1 1
4 7 9 2 4 1 5 10 5 10 7 6 2 9 8 9 2 10 10 6 4 3 2 9 4 8 3 2 8 8 7 9 5 2 6 4 10 5 7 9 10 10 7 4 9 9 2 8 2 6
5 8 8 2 6 6 9 10 1 1 9 3 9 10 1 9 8 7 7 7 5 3 4 5 3 2 10 7 8 10 8 8 9 3 2 2 10 ...

output:

53476

result:

ok 1 number(s): "53476"

Test #27:

score: 0
Accepted
time: 1049ms
memory: 6176kb

input:

50 50
3 8 1 10 1 6 3 3 8 8 5 1 9 6 4 2 4 10 1 5 4 3 2 8 6 1 2 3 5 1 2 10 5 1 9 10 4 4 8 5 5 6 8 9 8 1 5 5 5 3
4 9 4 3 10 5 2 5 6 2 1 9 7 5 3 4 3 4 9 10 3 3 5 1 5 5 9 9 1 6 8 1 6 6 7 2 1 7 10 8 4 7 8 9 8 5 10 10 10 2
6 2 9 3 10 8 9 5 7 2 8 2 1 3 9 2 10 10 6 3 10 4 10 9 1 6 10 8 9 7 10 4 7 2 8 9 7 3 3...

output:

49141

result:

ok 1 number(s): "49141"

Test #28:

score: 0
Accepted
time: 999ms
memory: 6192kb

input:

50 50
1 3 9 8 5 3 2 1 7 10 8 1 9 9 3 1 6 1 3 4 5 4 1 7 3 8 9 3 7 9 2 10 10 8 8 8 8 5 6 5 1 6 7 6 5 6 10 1 3 6
1 3 7 5 6 3 2 6 5 10 6 2 6 6 4 1 4 7 10 4 8 6 10 7 1 9 5 2 6 8 2 8 10 4 4 5 3 8 4 7 2 9 7 4 3 7 6 1 2 6
1 6 10 10 3 4 8 8 2 5 4 6 5 1 3 3 9 8 1 7 6 4 8 9 7 4 8 4 3 9 2 10 2 9 9 5 8 5 6 9 5 6...

output:

49743

result:

ok 1 number(s): "49743"

Test #29:

score: 0
Accepted
time: 902ms
memory: 6136kb

input:

50 50
2 9 7 9 4 9 5 9 7 2 8 10 5 2 2 9 7 2 6 4 10 6 2 3 9 3 2 10 6 7 10 5 8 3 7 9 7 6 5 7 7 1 10 7 8 4 3 9 7 9
9 1 5 9 3 2 4 9 2 8 7 2 4 8 1 3 3 4 4 10 4 3 4 7 5 9 10 8 5 10 8 10 1 4 9 8 4 7 6 10 9 3 8 6 8 4 2 9 7 3
7 6 3 3 9 4 4 4 9 7 5 8 9 1 7 7 8 9 1 1 7 8 6 10 4 3 6 10 9 8 9 3 3 1 6 2 8 9 9 6 1 ...

output:

56108

result:

ok 1 number(s): "56108"

Test #30:

score: 0
Accepted
time: 856ms
memory: 6084kb

input:

50 50
10 3 3 1 6 3 10 7 2 4 1 10 6 3 3 6 1 6 8 9 9 10 10 6 10 9 3 1 8 7 6 3 3 5 2 5 7 5 7 1 4 9 5 6 7 10 1 3 5 1
3 3 9 3 9 4 4 4 7 4 10 5 3 1 2 8 1 4 3 4 7 5 3 3 7 5 10 1 8 6 9 2 7 8 4 8 2 4 6 3 7 7 7 1 7 1 10 7 3 7
4 2 8 10 1 10 3 7 6 2 5 7 1 10 5 2 10 8 8 8 3 4 4 9 6 1 6 1 5 4 1 9 7 6 7 8 9 4 1 5 ...

output:

58373

result:

ok 1 number(s): "58373"

Test #31:

score: 0
Accepted
time: 887ms
memory: 6172kb

input:

50 50
10 8 7 10 9 10 7 9 8 7 1 3 10 2 10 9 8 4 6 7 7 10 5 7 7 2 10 6 5 7 2 8 4 2 4 3 6 6 10 8 5 3 10 2 6 7 2 9 7 4
5 4 4 10 5 9 1 5 10 9 8 6 8 3 3 6 6 8 4 8 6 1 8 5 2 9 6 4 5 10 3 8 4 1 6 4 4 10 4 2 5 4 9 1 6 3 6 8 7 1
8 6 9 1 10 6 8 4 10 4 10 8 3 5 9 3 9 10 6 4 4 5 2 3 6 9 6 3 3 7 5 4 6 9 3 5 5 2 4...

output:

57541

result:

ok 1 number(s): "57541"

Test #32:

score: 0
Accepted
time: 861ms
memory: 6192kb

input:

50 50
8 2 6 2 7 3 9 3 7 9 1 1 10 7 1 6 6 8 8 2 8 7 4 10 4 10 1 9 1 3 6 2 1 4 5 3 10 1 8 9 4 4 5 7 2 1 4 2 5 7
8 8 9 2 7 7 8 8 9 3 9 1 7 9 8 7 3 2 3 6 10 8 3 6 1 9 2 1 10 8 6 1 4 9 7 2 1 7 3 8 3 10 10 2 5 7 4 9 9 7
1 1 2 8 4 2 4 3 7 5 4 3 6 3 5 8 1 1 5 8 2 7 10 3 10 3 6 9 8 1 7 6 6 6 3 6 6 3 5 9 3 10...

output:

56369

result:

ok 1 number(s): "56369"

Test #33:

score: 0
Accepted
time: 3ms
memory: 6124kb

input:

50 50
994 478 621 47 258 702 48 709 325 437 589 483 431 49 309 64 259 541 443 819 743 753 463 739 139 805 731 414 806 378 616 875 313 977 194 56 649 833 296 4 321 45 757 606 390 324 834 500 577 576
425 981 353 983 867 784 70 661 756 43 959 432 842 533 45 75 897 987 246 707 569 71 795 589 902 12 266 ...

output:

1256165665

result:

ok 1 number(s): "1256165665"

Test #34:

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

input:

1 1
1
4

output:

0

result:

ok 1 number(s): "0"

Test #35:

score: 0
Accepted
time: 682ms
memory: 6324kb

input:

50 50
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

2427000000

result:

ok 1 number(s): "2427000000"

Test #36:

score: 0
Accepted
time: 1152ms
memory: 6200kb

input:

50 50
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

0

result:

ok 1 number(s): "0"

Test #37:

score: 0
Accepted
time: 1171ms
memory: 6200kb

input:

50 50
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

1000000

result:

ok 1 number(s): "1000000"