Submission #1045431

# Submission time Handle Problem Language Result Execution time Memory
1045431 2024-08-06T00:52:47 Z Darren0724 Portal (BOI24_portal) C++17
65 / 100
691 ms 5004 KB
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define rz resize
#define pb emplace_back
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int INF=9e18;
const int mod=1e9+7;
const int N=200005;
const int K=20;
const int C=2000005;

int gcd(int a,int b){
    return abs(__gcd(a,b));
}

 
int32_t main(){
    LCBorz;
    int n;cin>>n;
    if(n<=2){
        cout<<-1<<endl;
        return 0;
    }
    vector<pair<int,int>> v(n),v1(n);
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        v[i]={a,b};
    }
    sort(all(v));
    for(int i=1;i<n;i++){
        v[i].x-=v[0].x;
        v[i].y-=v[0].y;
    }
    int ans=-1;
    auto solve=[&](int i,int j)->void {
        if(v[i].y==0&&v[j].y==0){
            return;
        }
        if(v[i].y==0){
            ans=(ans==-1?v[i].x:gcd(v[i].x,ans));
            return;
        }
        if(v[j].y==0){
            ans=(ans==-1?v[j].x:gcd(v[j].x,ans));
            return;
        }
        int r1=v[j].y/gcd(v[i].y,v[j].y);
        int t=v[i].y*r1;
        int t1=t/v[j].y;
        int x1=abs(v[i].x*r1-v[j].x*t1);
        if(x1!=0)ans=(ans==-1?x1:gcd(ans,x1));
    };
    for(int i=0;i<10000000;i++){
        int g1=rnd()%(n-1)+1;
        int g2=rnd()%(n-1)+1;
        solve(g1,g2);
    }
    int g1=-1;
    for(int i=1;i<n;i++){
        if(v[i].y==0)continue;
        g1=(g1==-1?abs(v[i].y):gcd(g1,v[i].y));
    }
    //cout<<ans<<' '<<g1<<endl;
    cout<<(ans==-1?-1:ans*g1)<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 289 ms 432 KB Output is correct
20 Correct 371 ms 428 KB Output is correct
21 Correct 369 ms 348 KB Output is correct
22 Correct 322 ms 348 KB Output is correct
23 Correct 437 ms 344 KB Output is correct
24 Correct 334 ms 600 KB Output is correct
25 Correct 299 ms 348 KB Output is correct
26 Correct 313 ms 348 KB Output is correct
27 Correct 314 ms 348 KB Output is correct
28 Correct 334 ms 436 KB Output is correct
29 Correct 358 ms 348 KB Output is correct
30 Correct 392 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 357 ms 348 KB Output is correct
33 Correct 368 ms 348 KB Output is correct
34 Correct 326 ms 428 KB Output is correct
35 Correct 346 ms 344 KB Output is correct
36 Correct 370 ms 348 KB Output is correct
37 Correct 324 ms 348 KB Output is correct
38 Correct 394 ms 600 KB Output is correct
39 Correct 372 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 507 ms 3584 KB Output is correct
3 Correct 563 ms 3416 KB Output is correct
4 Correct 495 ms 3416 KB Output is correct
5 Correct 506 ms 3416 KB Output is correct
6 Correct 527 ms 3420 KB Output is correct
7 Correct 167 ms 3420 KB Output is correct
8 Correct 168 ms 3416 KB Output is correct
9 Correct 168 ms 3420 KB Output is correct
10 Correct 646 ms 3416 KB Output is correct
11 Correct 314 ms 3580 KB Output is correct
12 Correct 306 ms 3416 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 654 ms 3420 KB Output is correct
15 Correct 663 ms 3416 KB Output is correct
16 Correct 498 ms 3420 KB Output is correct
17 Correct 593 ms 3580 KB Output is correct
18 Correct 537 ms 3584 KB Output is correct
19 Correct 511 ms 3420 KB Output is correct
20 Correct 545 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 348 KB Output is correct
2 Correct 258 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 324 ms 348 KB Output is correct
5 Correct 373 ms 344 KB Output is correct
6 Correct 311 ms 440 KB Output is correct
7 Correct 398 ms 348 KB Output is correct
8 Correct 350 ms 344 KB Output is correct
9 Correct 356 ms 428 KB Output is correct
10 Correct 119 ms 348 KB Output is correct
11 Correct 363 ms 344 KB Output is correct
12 Correct 362 ms 348 KB Output is correct
13 Correct 358 ms 348 KB Output is correct
14 Correct 151 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 355 ms 348 KB Output is correct
17 Correct 380 ms 432 KB Output is correct
18 Correct 381 ms 348 KB Output is correct
19 Correct 408 ms 348 KB Output is correct
20 Correct 386 ms 348 KB Output is correct
21 Correct 316 ms 344 KB Output is correct
22 Correct 356 ms 348 KB Output is correct
23 Correct 373 ms 348 KB Output is correct
24 Correct 418 ms 348 KB Output is correct
25 Correct 376 ms 348 KB Output is correct
26 Correct 367 ms 436 KB Output is correct
27 Correct 366 ms 600 KB Output is correct
28 Correct 381 ms 348 KB Output is correct
29 Correct 377 ms 344 KB Output is correct
30 Correct 371 ms 348 KB Output is correct
31 Correct 381 ms 348 KB Output is correct
32 Correct 375 ms 344 KB Output is correct
33 Correct 356 ms 348 KB Output is correct
34 Correct 361 ms 436 KB Output is correct
35 Correct 364 ms 432 KB Output is correct
36 Correct 362 ms 348 KB Output is correct
37 Correct 365 ms 344 KB Output is correct
38 Correct 316 ms 432 KB Output is correct
39 Correct 284 ms 348 KB Output is correct
40 Correct 255 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 289 ms 432 KB Output is correct
20 Correct 371 ms 428 KB Output is correct
21 Correct 369 ms 348 KB Output is correct
22 Correct 322 ms 348 KB Output is correct
23 Correct 437 ms 344 KB Output is correct
24 Correct 334 ms 600 KB Output is correct
25 Correct 299 ms 348 KB Output is correct
26 Correct 313 ms 348 KB Output is correct
27 Correct 314 ms 348 KB Output is correct
28 Correct 334 ms 436 KB Output is correct
29 Correct 358 ms 348 KB Output is correct
30 Correct 392 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 357 ms 348 KB Output is correct
33 Correct 368 ms 348 KB Output is correct
34 Correct 326 ms 428 KB Output is correct
35 Correct 346 ms 344 KB Output is correct
36 Correct 370 ms 348 KB Output is correct
37 Correct 324 ms 348 KB Output is correct
38 Correct 394 ms 600 KB Output is correct
39 Correct 372 ms 348 KB Output is correct
40 Correct 261 ms 348 KB Output is correct
41 Correct 258 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 324 ms 348 KB Output is correct
44 Correct 373 ms 344 KB Output is correct
45 Correct 311 ms 440 KB Output is correct
46 Correct 398 ms 348 KB Output is correct
47 Correct 350 ms 344 KB Output is correct
48 Correct 356 ms 428 KB Output is correct
49 Correct 119 ms 348 KB Output is correct
50 Correct 363 ms 344 KB Output is correct
51 Correct 362 ms 348 KB Output is correct
52 Correct 358 ms 348 KB Output is correct
53 Correct 151 ms 344 KB Output is correct
54 Correct 0 ms 344 KB Output is correct
55 Correct 355 ms 348 KB Output is correct
56 Correct 380 ms 432 KB Output is correct
57 Correct 381 ms 348 KB Output is correct
58 Correct 408 ms 348 KB Output is correct
59 Correct 386 ms 348 KB Output is correct
60 Correct 316 ms 344 KB Output is correct
61 Correct 356 ms 348 KB Output is correct
62 Correct 373 ms 348 KB Output is correct
63 Correct 418 ms 348 KB Output is correct
64 Correct 376 ms 348 KB Output is correct
65 Correct 367 ms 436 KB Output is correct
66 Correct 366 ms 600 KB Output is correct
67 Correct 381 ms 348 KB Output is correct
68 Correct 377 ms 344 KB Output is correct
69 Correct 371 ms 348 KB Output is correct
70 Correct 381 ms 348 KB Output is correct
71 Correct 375 ms 344 KB Output is correct
72 Correct 356 ms 348 KB Output is correct
73 Correct 361 ms 436 KB Output is correct
74 Correct 364 ms 432 KB Output is correct
75 Correct 362 ms 348 KB Output is correct
76 Correct 365 ms 344 KB Output is correct
77 Correct 316 ms 432 KB Output is correct
78 Correct 284 ms 348 KB Output is correct
79 Correct 255 ms 348 KB Output is correct
80 Correct 637 ms 348 KB Output is correct
81 Correct 657 ms 344 KB Output is correct
82 Correct 470 ms 344 KB Output is correct
83 Correct 473 ms 344 KB Output is correct
84 Correct 524 ms 468 KB Output is correct
85 Correct 463 ms 348 KB Output is correct
86 Correct 477 ms 348 KB Output is correct
87 Correct 623 ms 348 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 634 ms 348 KB Output is correct
90 Correct 665 ms 600 KB Output is correct
91 Correct 637 ms 348 KB Output is correct
92 Correct 680 ms 348 KB Output is correct
93 Correct 676 ms 344 KB Output is correct
94 Correct 641 ms 348 KB Output is correct
95 Correct 664 ms 496 KB Output is correct
96 Correct 595 ms 344 KB Output is correct
97 Correct 577 ms 344 KB Output is correct
98 Correct 612 ms 348 KB Output is correct
99 Correct 570 ms 496 KB Output is correct
100 Correct 600 ms 348 KB Output is correct
101 Correct 546 ms 592 KB Output is correct
102 Correct 573 ms 348 KB Output is correct
103 Correct 593 ms 344 KB Output is correct
104 Correct 567 ms 344 KB Output is correct
105 Correct 585 ms 348 KB Output is correct
106 Correct 548 ms 348 KB Output is correct
107 Correct 578 ms 344 KB Output is correct
108 Correct 568 ms 344 KB Output is correct
109 Correct 611 ms 348 KB Output is correct
110 Correct 594 ms 348 KB Output is correct
111 Correct 417 ms 348 KB Output is correct
112 Correct 450 ms 344 KB Output is correct
113 Correct 421 ms 432 KB Output is correct
114 Correct 605 ms 348 KB Output is correct
115 Correct 641 ms 496 KB Output is correct
116 Correct 615 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 289 ms 432 KB Output is correct
20 Correct 371 ms 428 KB Output is correct
21 Correct 369 ms 348 KB Output is correct
22 Correct 322 ms 348 KB Output is correct
23 Correct 437 ms 344 KB Output is correct
24 Correct 334 ms 600 KB Output is correct
25 Correct 299 ms 348 KB Output is correct
26 Correct 313 ms 348 KB Output is correct
27 Correct 314 ms 348 KB Output is correct
28 Correct 334 ms 436 KB Output is correct
29 Correct 358 ms 348 KB Output is correct
30 Correct 392 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 357 ms 348 KB Output is correct
33 Correct 368 ms 348 KB Output is correct
34 Correct 326 ms 428 KB Output is correct
35 Correct 346 ms 344 KB Output is correct
36 Correct 370 ms 348 KB Output is correct
37 Correct 324 ms 348 KB Output is correct
38 Correct 394 ms 600 KB Output is correct
39 Correct 372 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 507 ms 3584 KB Output is correct
42 Correct 563 ms 3416 KB Output is correct
43 Correct 495 ms 3416 KB Output is correct
44 Correct 506 ms 3416 KB Output is correct
45 Correct 527 ms 3420 KB Output is correct
46 Correct 167 ms 3420 KB Output is correct
47 Correct 168 ms 3416 KB Output is correct
48 Correct 168 ms 3420 KB Output is correct
49 Correct 646 ms 3416 KB Output is correct
50 Correct 314 ms 3580 KB Output is correct
51 Correct 306 ms 3416 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 654 ms 3420 KB Output is correct
54 Correct 663 ms 3416 KB Output is correct
55 Correct 498 ms 3420 KB Output is correct
56 Correct 593 ms 3580 KB Output is correct
57 Correct 537 ms 3584 KB Output is correct
58 Correct 511 ms 3420 KB Output is correct
59 Correct 545 ms 3420 KB Output is correct
60 Correct 261 ms 348 KB Output is correct
61 Correct 258 ms 344 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 324 ms 348 KB Output is correct
64 Correct 373 ms 344 KB Output is correct
65 Correct 311 ms 440 KB Output is correct
66 Correct 398 ms 348 KB Output is correct
67 Correct 350 ms 344 KB Output is correct
68 Correct 356 ms 428 KB Output is correct
69 Correct 119 ms 348 KB Output is correct
70 Correct 363 ms 344 KB Output is correct
71 Correct 362 ms 348 KB Output is correct
72 Correct 358 ms 348 KB Output is correct
73 Correct 151 ms 344 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 355 ms 348 KB Output is correct
76 Correct 380 ms 432 KB Output is correct
77 Correct 381 ms 348 KB Output is correct
78 Correct 408 ms 348 KB Output is correct
79 Correct 386 ms 348 KB Output is correct
80 Correct 316 ms 344 KB Output is correct
81 Correct 356 ms 348 KB Output is correct
82 Correct 373 ms 348 KB Output is correct
83 Correct 418 ms 348 KB Output is correct
84 Correct 376 ms 348 KB Output is correct
85 Correct 367 ms 436 KB Output is correct
86 Correct 366 ms 600 KB Output is correct
87 Correct 381 ms 348 KB Output is correct
88 Correct 377 ms 344 KB Output is correct
89 Correct 371 ms 348 KB Output is correct
90 Correct 381 ms 348 KB Output is correct
91 Correct 375 ms 344 KB Output is correct
92 Correct 356 ms 348 KB Output is correct
93 Correct 361 ms 436 KB Output is correct
94 Correct 364 ms 432 KB Output is correct
95 Correct 362 ms 348 KB Output is correct
96 Correct 365 ms 344 KB Output is correct
97 Correct 316 ms 432 KB Output is correct
98 Correct 284 ms 348 KB Output is correct
99 Correct 255 ms 348 KB Output is correct
100 Correct 637 ms 348 KB Output is correct
101 Correct 657 ms 344 KB Output is correct
102 Correct 470 ms 344 KB Output is correct
103 Correct 473 ms 344 KB Output is correct
104 Correct 524 ms 468 KB Output is correct
105 Correct 463 ms 348 KB Output is correct
106 Correct 477 ms 348 KB Output is correct
107 Correct 623 ms 348 KB Output is correct
108 Correct 0 ms 344 KB Output is correct
109 Correct 634 ms 348 KB Output is correct
110 Correct 665 ms 600 KB Output is correct
111 Correct 637 ms 348 KB Output is correct
112 Correct 680 ms 348 KB Output is correct
113 Correct 676 ms 344 KB Output is correct
114 Correct 641 ms 348 KB Output is correct
115 Correct 664 ms 496 KB Output is correct
116 Correct 595 ms 344 KB Output is correct
117 Correct 577 ms 344 KB Output is correct
118 Correct 612 ms 348 KB Output is correct
119 Correct 570 ms 496 KB Output is correct
120 Correct 600 ms 348 KB Output is correct
121 Correct 546 ms 592 KB Output is correct
122 Correct 573 ms 348 KB Output is correct
123 Correct 593 ms 344 KB Output is correct
124 Correct 567 ms 344 KB Output is correct
125 Correct 585 ms 348 KB Output is correct
126 Correct 548 ms 348 KB Output is correct
127 Correct 578 ms 344 KB Output is correct
128 Correct 568 ms 344 KB Output is correct
129 Correct 611 ms 348 KB Output is correct
130 Correct 594 ms 348 KB Output is correct
131 Correct 417 ms 348 KB Output is correct
132 Correct 450 ms 344 KB Output is correct
133 Correct 421 ms 432 KB Output is correct
134 Correct 605 ms 348 KB Output is correct
135 Correct 641 ms 496 KB Output is correct
136 Correct 615 ms 348 KB Output is correct
137 Correct 650 ms 4952 KB Output is correct
138 Correct 589 ms 4956 KB Output is correct
139 Correct 637 ms 5004 KB Output is correct
140 Correct 645 ms 4868 KB Output is correct
141 Correct 657 ms 4956 KB Output is correct
142 Correct 555 ms 860 KB Output is correct
143 Correct 539 ms 860 KB Output is correct
144 Correct 534 ms 864 KB Output is correct
145 Correct 540 ms 856 KB Output is correct
146 Correct 691 ms 912 KB Output is correct
147 Correct 614 ms 908 KB Output is correct
148 Correct 0 ms 344 KB Output is correct
149 Correct 635 ms 4956 KB Output is correct
150 Correct 676 ms 4952 KB Output is correct
151 Correct 596 ms 4956 KB Output is correct
152 Correct 662 ms 4952 KB Output is correct
153 Correct 667 ms 4952 KB Output is correct
154 Correct 591 ms 4956 KB Output is correct
155 Correct 657 ms 4996 KB Output is correct
156 Correct 629 ms 4444 KB Output is correct
157 Correct 617 ms 4440 KB Output is correct
158 Correct 604 ms 4440 KB Output is correct
159 Correct 649 ms 4444 KB Output is correct
160 Correct 596 ms 4444 KB Output is correct
161 Correct 631 ms 4604 KB Output is correct
162 Correct 611 ms 4444 KB Output is correct
163 Correct 640 ms 4444 KB Output is correct
164 Correct 596 ms 4440 KB Output is correct
165 Correct 576 ms 4360 KB Output is correct
166 Correct 598 ms 4260 KB Output is correct
167 Correct 615 ms 4620 KB Output is correct
168 Correct 633 ms 4188 KB Output is correct
169 Incorrect 561 ms 4184 KB Output isn't correct
170 Halted 0 ms 0 KB -