QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350542#8208. Beer Circuitsucup-team1198#TL 916ms52084kbC++207.6kb2024-03-10 20:01:232024-03-10 20:01:24

Judging History

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

  • [2024-03-10 20:01:24]
  • 评测
  • 测评结果:TL
  • 用时:916ms
  • 内存:52084kb
  • [2024-03-10 20:01:23]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

struct Point{
    long long x, y;
    Point(long long x, long long y): x(x), y(y) {}
    Point(): x(0), y(0) {}
};

Point operator+(const Point& a, const Point& b) {
    return Point(a.x + b.x, a.y + b.y);
}

Point operator-(const Point& a, const Point& b) {
    return Point(a.x - b.x, a.y - b.y);
}

long long cross(const Point& a, const Point& b) {
    return a.x * b.y - a.y * b.x;
}

long long square_len(const Point& P) {
    return P.x * P.x + P.y * P.y;
}

const double EPS = 1e-8;

const int MAXN = 200200;

vector<int> G[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector<Point> A(n);
    for (int i = 0; i < n; ++i)
        cin >> A[i].x >> A[i].y;
    random_shuffle(A.begin(), A.end());

    auto get_triangle_sz = [](const Point& A, const Point& B, const Point& C) {
        return max(square_len(A - B), max(square_len(B - C), square_len(C - A)));
    };

    long long min_d = get_triangle_sz(A[0], A[1], A[2]);
    int total = 0;
    double sz = sqrt(min_d) + EPS;
    vector<int> near;
    map<pair<int, int>, vector<int>> points;
    for (int i = 0; i < n; ++i) {
        int cur_x = floor(A[i].x / sz), cur_y = floor(A[i].y / sz);
        for (int dx = -1; dx <= 1; ++dx) {
            for (int dy = -1; dy <= 1; ++dy) {
                auto tmp = points.find(make_pair(cur_x + dx, cur_y + dy));
                if (tmp != points.end()) {
                    for (int j : tmp->second)
                        near.emplace_back(j);
                }
            }
        }
        long long bbest = min_d;
        int best_cnt = 0;
        for (int j = 0; j < near.size(); ++j) {
            for (int k = j + 1; k < near.size(); ++k) {
                long long cur = get_triangle_sz(A[i], A[near[j]], A[near[k]]);
                if (cur == bbest) {
                    ++best_cnt;
                } else if (cur < bbest) {
                    bbest = cur;
                    best_cnt = 1;
                }
            }
        }
        near.clear();
        if (bbest < min_d) {
            min_d = bbest;
            total = best_cnt;
            sz = sqrt(min_d) + EPS;
            points.clear();
            for (int j = 0; j <= i; ++j) {
                int cur_x = floor(A[j].x / sz), cur_y = floor(A[j].y / sz);
                points[make_pair(cur_x, cur_y)].emplace_back(j);
            }
        } else {
            total += best_cnt;
            points[make_pair(cur_x, cur_y)].emplace_back(i);
        }
    }
    vector<pair<int, int>> edges;
    for (int i = 0; i < n; ++i) {
        int cur_x = floor(A[i].x / sz), cur_y = floor(A[i].y / sz);
        for (int dx = -1; dx <= 1; ++dx) {
            for (int dy = -1; dy <= 1; ++dy) {
                auto tmp = points.find(make_pair(cur_x + dx, cur_y + dy));
                if (tmp != points.end()) {
                    for (int j : tmp->second) {
                        if (j < i && square_len(A[i] - A[j]) < min_d)
                            edges.emplace_back(j, i);
                    }
                }
            }
        }
    }

    long long ans_d = min_d;
    int ans_len = 3;
    long long ans_cnt = total;

    sort(edges.begin(), edges.end(), [&A](const pair<int, int>& a, const pair<int, int>& b) {
        return square_len(A[a.first] - A[a.second]) < square_len(A[b.first] - A[b.second]);
    });
    int m = edges.size();

    vector<vector<pair<int, int>>> all_edges(n);
    for (int i = 0; i < m; ++i) {
        all_edges[edges[i].first].emplace_back(edges[i].second, i);
        all_edges[edges[i].second].emplace_back(edges[i].first, i);   
    }

    vector<pair<int, int>> dps(m);
    // len, cnt
    // (0, 0) - NONE
    vector<int> dist1(n);
    vector<int> path_cnt1(n);
    vector<int> timer_used1(n, -1);
    vector<int> dist2(n);
    vector<int> path_cnt2(n);
    vector<int> timer_used2(n, -1);
    deque<int> Q;
    vector<int> interesting;
    long long mx_len = ans_d;
    for (int i = 0; i < m; ++i) {
        auto [u, v] = edges[i];
        long long cur_len = square_len(A[u] - A[v]);
        if (cur_len > mx_len)
            break;
        if (dps[i].second) {
            mx_len = cur_len;
            if (cur_len < ans_d) {
                ans_d = cur_len;
                ans_len = dps[i].first;
                ans_cnt = dps[i].second;
            } else if (cur_len == ans_d) {
                if (ans_len > dps[i].first) {
                    ans_len = dps[i].first;
                    ans_cnt = dps[i].second;
                } else if (ans_len == dps[i].first) {
                    ans_cnt += dps[i].second;
                }
            }
        }
        G[u].emplace_back(v);
        G[v].emplace_back(u);

        timer_used1[u] = i;
        Q.emplace_back(u);
        dist1[u] = 0;
        path_cnt1[u] = 1;
        while (!Q.empty()) {
            int cur = Q.front();
            interesting.emplace_back(cur);
            Q.pop_front();
            if (dist1[cur] == k - 1)
                continue;
            for (int x : G[cur]) {
                if (timer_used1[x] != i) {
                    timer_used1[x] = i;
                    dist1[x] = dist1[cur] + 1;
                    path_cnt1[x] = path_cnt1[cur];
                    Q.emplace_back(x);
                } else if (dist1[x] == dist1[cur] + 1) {
                    path_cnt1[x] += path_cnt1[cur];
                }
            }
        }

        timer_used2[v] = i;
        Q.emplace_back(v);
        dist2[v] = 0;
        path_cnt2[v] = 1;
        while (!Q.empty()) {
            int cur = Q.front();
            Q.pop_front();
            if (dist2[cur] == k - 1)
                continue;
            for (int x : G[cur]) {
                if (timer_used2[x] != i) {
                    timer_used2[x] = i;
                    dist2[x] = dist2[cur] + 1;
                    path_cnt2[x] = path_cnt2[cur];
                    Q.emplace_back(x);
                } else if (dist2[x] == dist2[cur] + 1) {
                    path_cnt2[x] += path_cnt2[cur];
                }
            }
        }

        sort(interesting.begin(), interesting.end());
        interesting.resize(unique(interesting.begin(), interesting.end()) - interesting.begin());
        for (int a : interesting) {
            for (auto [b, j] : all_edges[a]) {
                if (j <= i)
                    continue;
                if (timer_used2[b] == i) {
                    if (dist1[a] + dist2[b] <= k - 1) {
                        pair<int, int> cur(dist1[a] + dist2[b] + 2, path_cnt1[a] * path_cnt2[b]);
                        //cout << "trying " << a << ' ' << b << ' ' << cur.first << ' ' << cur.second << '\n';
                        if (dps[j].first == 0) {
                            dps[j] = cur;
                        } else if (dps[j].first > cur.first) {
                            dps[j] = cur;
                        } else if (dps[j].first == cur.first)
                            dps[j].second += cur.second;
                    }
                }
            }
        }
        interesting.clear();
    }

    cout << ans_d << '\n' << ans_len << '\n' << ans_cnt * 2 * ans_len << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3
0 0
2 2
1000000000 1000000000

output:

2000000000000000000
3
6

result:

ok 3 number(s): "2000000000000000000 3 6"

Test #2:

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

input:

8 5
5 5
5 7
7 7
3 7
2 5
8 5
3 4
7 4

output:

5
5
20

result:

ok 3 number(s): "5 5 20"

Test #3:

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

input:

10 5
1 4
4 4
3 8
5 1
6 5
7 1
0 6
2 2
2 1
3 0

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #4:

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

input:

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

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #5:

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

input:

10 5
2 0
5 1
2 7
5 0
1 10
0 7
5 8
7 3
6 2
0 4

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #6:

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

input:

10 5
8 1
3 2
7 3
10 4
4 1
7 6
3 1
7 2
10 0
6 7

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #7:

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

input:

10 5
6 6
9 10
8 3
1 0
3 0
1 1
5 9
4 1
4 6
8 6

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #8:

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

input:

10 5
8 4
0 3
2 3
10 0
3 6
0 4
8 3
8 8
0 2
0 1

output:

4
3
12

result:

ok 3 number(s): "4 3 12"

Test #9:

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

input:

10 5
6 6
5 8
3 6
0 0
2 8
6 8
10 7
1 7
5 7
6 7

output:

1
4
8

result:

ok 3 number(s): "1 4 8"

Test #10:

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

input:

10 5
1 8
7 8
8 6
6 0
9 6
8 10
9 0
5 9
4 2
8 2

output:

8
3
6

result:

ok 3 number(s): "8 3 6"

Test #11:

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

input:

10 5
10 9
1 2
1 9
8 7
8 2
7 2
1 8
9 8
9 7
3 1

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #12:

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

input:

10 5
0 10
6 6
10 8
9 7
0 9
8 3
5 0
7 10
3 2
3 4

output:

13
3
6

result:

ok 3 number(s): "13 3 6"

Test #13:

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

input:

10 5
9 4
5 0
5 4
0 3
6 0
6 6
3 7
2 3
0 1
5 9

output:

8
3
6

result:

ok 3 number(s): "8 3 6"

Test #14:

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

input:

10 5
7 10
6 5
9 3
6 3
4 5
6 4
2 2
7 0
7 4
5 3

output:

2
3
18

result:

ok 3 number(s): "2 3 18"

Test #15:

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

input:

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

output:

5
3
12

result:

ok 3 number(s): "5 3 12"

Test #16:

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

input:

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

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #17:

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

input:

10 5
2 7
1 7
9 10
7 10
0 9
8 7
5 6
8 10
5 2
0 0

output:

4
3
6

result:

ok 3 number(s): "4 3 6"

Test #18:

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

input:

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

output:

2
3
6

result:

ok 3 number(s): "2 3 6"

Test #19:

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

input:

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

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #20:

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

input:

10 5
4 8
3 1
1 5
4 10
0 8
8 5
6 6
6 2
10 0
2 8

output:

8
3
6

result:

ok 3 number(s): "8 3 6"

Test #21:

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

input:

10 5
6 9
5 9
3 5
2 3
1 4
6 7
0 9
2 5
3 7
1 6

output:

4
3
12

result:

ok 3 number(s): "4 3 12"

Test #22:

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

input:

10 5
2 10
9 5
7 7
6 2
7 2
5 9
3 8
7 10
6 0
1 1

output:

5
3
6

result:

ok 3 number(s): "5 3 6"

Test #23:

score: 0
Accepted
time: 745ms
memory: 50496kb

input:

199692 3
500136792 500000000
499931604 500118465
499931604 499881535
500557553 499600008
500352365 499718473
500352365 499481543
500978314 499200016
500773126 499318481
500773126 499081551
501399075 498800024
501193887 498918489
501193887 498681559
501819836 498400032
501614648 498518497
501614648 4...

output:

56136071569
3
399384

result:

ok 3 number(s): "56136071569 3 399384"

Test #24:

score: 0
Accepted
time: 820ms
memory: 52084kb

input:

198916 4
500024820 500000000
500000000 500024820
499975180 500000000
500000000 499975180
500110708 499936963
500085888 499961783
500061068 499936963
500085888 499912143
500196596 499873926
500171776 499898746
500146956 499873926
500171776 499849106
500282484 499810889
500257664 499835709
500232844 4...

output:

1232064800
4
397832

result:

ok 3 number(s): "1232064800 4 397832"

Test #25:

score: 0
Accepted
time: 840ms
memory: 50488kb

input:

200000 5
500243124 500000000
500075129 500231225
499803309 500142905
499803309 499857095
500075129 499768775
500748155 499046283
500580160 499277508
500308340 499189188
500308340 498903378
500580160 498815058
501253186 498092566
501085191 498323791
500813371 498235471
500813371 497949661
501085191 4...

output:

81687356100
5
400000

result:

ok 3 number(s): "81687356100 5 400000"

Test #26:

score: 0
Accepted
time: 799ms
memory: 49292kb

input:

198744 6
500157690 500000000
500078845 500136563
499921155 500136563
499842310 500000000
499921155 499863437
500078845 499863437
500935173 499831340
500856328 499967903
500698638 499967903
500619793 499831340
500698638 499694777
500856328 499694777
501712656 499662680
501633811 499799243
501476121 4...

output:

24866136100
6
397488

result:

ok 3 number(s): "24866136100 6 397488"

Test #27:

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

input:

199927 7
500278028 500000000
500173347 500217371
499938133 500271057
499749505 500120632
499749505 499879368
499938133 499728943
500173347 499782629
501459060 499512861
501354379 499730232
501119165 499783918
500930537 499633493
500930537 499392229
501119165 499241804
501354379 499295490
502640092 4...

output:

58208317696
7
399854

result:

ok 3 number(s): "58208317696 7 399854"

Test #28:

score: 0
Accepted
time: 851ms
memory: 49300kb

input:

199712 8
500197494 500000000
500139649 500139649
500000000 500197494
499860351 500139649
499802506 500000000
499860351 499860351
500000000 499802506
500139649 499860351
501140007 499757547
501082162 499897196
500942513 499955041
500802864 499897196
500745019 499757547
500802864 499617898
500942513 4...

output:

22847887226
8
399424

result:

ok 3 number(s): "22847887226 8 399424"

Test #29:

score: 0
Accepted
time: 836ms
memory: 48716kb

input:

199809 9
500517211 500000000
500396206 500332456
500089812 500509353
499741395 500447918
499513981 500176896
499513981 499823104
499741395 499552082
500089812 499490647
500396206 499667544
502059676 498439198
501938671 498771654
501632277 498948551
501283860 498887116
501056446 498616094
501056446 4...

output:

125170051880
9
399618

result:

ok 3 number(s): "125170051880 9 399618"

Test #30:

score: 0
Accepted
time: 806ms
memory: 48268kb

input:

198810 10
500213830 500000000
500172992 500125686
500066077 500203364
499933923 500203364
499827008 500125686
499786170 500000000
499827008 499874314
499933923 499796636
500066077 499796636
500172992 499874314
500868929 499372119
500828091 499497805
500721176 499575483
500589022 499575483
500482107 ...

output:

17464712840
10
397620

result:

ok 3 number(s): "17464712840 10 397620"

Test #31:

score: 0
Accepted
time: 860ms
memory: 48172kb

input:

197516 11
500355273 500000000
500298874 500192075
500147585 500323167
499949440 500351656
499767346 500268497
499659118 500100092
499659118 499899908
499767346 499731503
499949440 499648344
500147585 499676833
500298874 499807925
501503078 499016166
501446679 499208241
501295390 499339333
501097245 ...

output:

40073652826
11
395032

result:

ok 3 number(s): "40073652826 11 395032"

Test #32:

score: 0
Accepted
time: 859ms
memory: 48772kb

input:

199692 12
500287748 500000000
500249197 500143874
500143874 500249197
500000000 500287748
499856126 500249197
499750803 500143874
499712252 500000000
499750803 499856126
499856126 499750803
500000000 499712252
500143874 499750803
500249197 499856126
501616606 499602368
501578055 499746242
501472732 ...

output:

22185907477
12
399384

result:

ok 3 number(s): "22185907477 12 399384"

Test #33:

score: 0
Accepted
time: 869ms
memory: 48464kb

input:

199888 13
500214891 500000000
500190276 500099864
500122072 500176851
500025902 500213324
499923799 500200926
499839152 500142499
499791354 500051426
499791354 499948574
499839152 499857501
499923799 499799074
500025902 499786676
500122072 499823149
500190276 499900136
500400819 498896581
500376204 ...

output:

10578948629
13
399776

result:

ok 3 number(s): "10578948629 13 399776"

Test #34:

score: 0
Accepted
time: 867ms
memory: 48004kb

input:

198254 14
500466462 500000000
500420268 500202390
500290834 500364695
500103797 500454767
499896203 500454767
499709166 500364695
499579732 500202390
499533538 500000000
499579732 499797610
499709166 499635305
499896203 499545233
500103797 499545233
500290834 499635305
500420268 499797610
501174191 ...

output:

43096073381
14
396508

result:

ok 3 number(s): "43096073381 14 396508"

Test #35:

score: 0
Accepted
time: 839ms
memory: 48104kb

input:

198375 15
500469143 500000000
500428583 500190817
500313918 500348641
500144973 500446181
499950962 500466573
499765429 500406289
499620456 500275755
499541109 500097540
499541109 499902460
499620456 499724245
499765429 499593711
499950962 499533427
500144973 499553819
500313918 499651359
500428583 ...

output:

38056654745
15
396750

result:

ok 3 number(s): "38056654745 15 396750"

Test #36:

score: 0
Accepted
time: 864ms
memory: 47660kb

input:

197136 16
500209439 500000000
500193496 500080148
500148095 500148095
500080148 500193496
500000000 500209439
499919852 500193496
499851905 500148095
499806504 500080148
499790561 500000000
499806504 499919852
499851905 499851905
499919852 499806504
500000000 499790561
500080148 499806504
500148095 ...

output:

6678045610
16
394272

result:

ok 3 number(s): "6678045610 16 394272"

Test #37:

score: 0
Accepted
time: 877ms
memory: 47880kb

input:

198288 17
500145782 500000000
500135938 500052662
500107734 500098213
500064980 500130499
500013451 500145160
499960105 500140217
499912147 500116336
499876054 500076744
499856700 500026787
499856700 499973213
499876054 499923256
499912147 499883664
499960105 499859783
500013451 499854840
500064980 ...

output:

2870359217
17
396576

result:

ok 3 number(s): "2870359217 17 396576"

Test #38:

score: 0
Accepted
time: 881ms
memory: 47972kb

input:

198450 18
500408063 500000000
500383453 500139565
500312594 500262297
500204031 500353392
500070859 500401863
499929141 500401863
499795969 500353392
499687406 500262297
499616547 500139565
499591937 500000000
499616547 499860435
499687406 499737703
499795969 499646608
499929141 499598137
500070859 ...

output:

20084223994
18
396900

result:

ok 3 number(s): "20084223994 18 396900"

Test #39:

score: 0
Accepted
time: 901ms
memory: 47848kb

input:

197676 19
500266376 500000000
500251943 500086492
500210208 500163612
500145694 500223001
500065391 500258225
499978003 500265467
499892998 500243940
499819588 500195979
499765729 500126781
499737257 500043844
499737257 499956156
499765729 499873219
499819588 499804021
499892998 499756060
499978003 ...

output:

7689304625
19
395352

result:

ok 3 number(s): "7689304625 19 395352"

Test #40:

score: 0
Accepted
time: 837ms
memory: 48308kb

input:

200000 20
500471804 500000000
500448712 500145795
500381697 500277319
500277319 500381697
500145795 500448712
500000000 500471804
499854205 500448712
499722681 500381697
499618303 500277319
499551288 500145795
499528196 500000000
499551288 499854205
499618303 499722681
499722681 499618303
499854205 ...

output:

21789572801
20
400000

result:

ok 3 number(s): "21789572801 20 400000"

Test #41:

score: 0
Accepted
time: 916ms
memory: 47520kb

input:

196830 30
500478309 500000000
500467856 500099446
500436957 500194545
500386960 500281142
500320051 500355452
500239154 500414227
500147805 500454898
500049996 500475688
499950004 500475688
499852195 500454898
499760846 500414227
499679949 500355452
499613040 500281142
499563043 500194545
499532144 ...

output:

9998825234
30
393660

result:

ok 3 number(s): "9998825234 30 393660"

Test #42:

score: 0
Accepted
time: 749ms
memory: 47564kb

input:

199980 30
187518 500000000
187501 500001125
184276 500015254
183803 500016275
175109 500027870
174262 500028610
161604 500035667
160529 500035999
146095 500037298
144978 500037163
131264 500032479
130298 500031901
119674 500022044
119027 500021124
113332 500007797
113114 500006693
113332 499992203
1...

output:

210044785
30
120

result:

ok 3 number(s): "210044785 30 120"

Test #43:

score: 0
Accepted
time: 717ms
memory: 46832kb

input:

199976 28
175020 500000000
175004 500001050
171554 500015188
171084 500016127
161841 500027367
161010 500028010
147805 500034126
146778 500034345
132227 500034126
131207 500033877
118191 500027367
117380 500026700
108478 500015188
108037 500014235
105012 500000000
105028 499998950
108478 499984812
1...

output:

211796356
28
399952

result:

ok 3 number(s): "211796356 28 399952"

Test #44:

score: 0
Accepted
time: 782ms
memory: 46800kb

input:

199992 26
162506 500000000
162491 500000975
158783 500015104
158317 500015960
148468 500026748
147657 500027290
133923 500032264
132953 500032367
118480 500030389
117574 500030030
105678 500021552
105042 500020813
98448 500007778
98229 500006828
98448 499992222
98696 499991279
105678 499978448
10633...

output:

213392061
26
399984

result:

ok 3 number(s): "213392061 26 399984"

Test #45:

score: -100
Time Limit Exceeded

input:

49729 30
500000000 500000000
500753821 498954062
501507642 497908124
502261463 496862186
503015284 495816248
503769105 494770310
504522926 493724372
505276747 492678434
506030568 491632496
506784389 490586558
507538210 489540620
508292031 488494682
509045852 487448744
509799673 486402806
510553494 4...

output:


result: