답안 #1045434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045434 2024-08-06T00:56:13 Z Darren0724 Portal (BOI24_portal) C++17
65 / 100
734 ms 4756 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 {
        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));
    };
    vector<int> t;
    for(int i=1;i<n;i++){
        if(v[i].y==0){
            ans=(ans==-1?v[i].x:gcd(v[i].x,ans));
            continue;
        }
        t.push_back(i);
    }
    int sz=t.size();
    if(sz==0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<10000000;i++){
        int g1=rnd()%sz;
        int g2=rnd()%sz;
        solve(t[g1],t[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;
}
# 결과 실행 시간 메모리 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 348 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 508 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
# 결과 실행 시간 메모리 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 348 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 508 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 274 ms 432 KB Output is correct
20 Correct 408 ms 344 KB Output is correct
21 Correct 393 ms 432 KB Output is correct
22 Correct 329 ms 436 KB Output is correct
23 Correct 446 ms 348 KB Output is correct
24 Correct 349 ms 344 KB Output is correct
25 Correct 313 ms 348 KB Output is correct
26 Correct 332 ms 348 KB Output is correct
27 Correct 354 ms 436 KB Output is correct
28 Correct 339 ms 436 KB Output is correct
29 Correct 380 ms 344 KB Output is correct
30 Correct 392 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 367 ms 348 KB Output is correct
33 Correct 375 ms 348 KB Output is correct
34 Correct 330 ms 348 KB Output is correct
35 Correct 354 ms 344 KB Output is correct
36 Correct 384 ms 344 KB Output is correct
37 Correct 338 ms 348 KB Output is correct
38 Correct 399 ms 432 KB Output is correct
39 Correct 382 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 596 ms 4492 KB Output is correct
3 Correct 571 ms 4564 KB Output is correct
4 Correct 548 ms 4564 KB Output is correct
5 Correct 577 ms 4756 KB Output is correct
6 Correct 563 ms 4572 KB Output is correct
7 Correct 16 ms 3420 KB Output is correct
8 Correct 17 ms 3612 KB Output is correct
9 Correct 18 ms 3416 KB Output is correct
10 Correct 682 ms 4572 KB Output is correct
11 Correct 316 ms 4064 KB Output is correct
12 Correct 310 ms 4064 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 682 ms 4744 KB Output is correct
15 Correct 675 ms 4572 KB Output is correct
16 Correct 553 ms 4756 KB Output is correct
17 Correct 629 ms 4572 KB Output is correct
18 Correct 579 ms 4568 KB Output is correct
19 Correct 560 ms 4572 KB Output is correct
20 Correct 558 ms 4572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 344 KB Output is correct
2 Correct 295 ms 432 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 338 ms 436 KB Output is correct
5 Correct 385 ms 444 KB Output is correct
6 Correct 323 ms 344 KB Output is correct
7 Correct 423 ms 344 KB Output is correct
8 Correct 352 ms 344 KB Output is correct
9 Correct 361 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 393 ms 348 KB Output is correct
12 Correct 366 ms 348 KB Output is correct
13 Correct 381 ms 348 KB Output is correct
14 Correct 174 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 364 ms 432 KB Output is correct
17 Correct 361 ms 596 KB Output is correct
18 Correct 403 ms 432 KB Output is correct
19 Correct 426 ms 344 KB Output is correct
20 Correct 402 ms 436 KB Output is correct
21 Correct 338 ms 348 KB Output is correct
22 Correct 358 ms 436 KB Output is correct
23 Correct 380 ms 348 KB Output is correct
24 Correct 399 ms 344 KB Output is correct
25 Correct 403 ms 348 KB Output is correct
26 Correct 370 ms 348 KB Output is correct
27 Correct 373 ms 436 KB Output is correct
28 Correct 376 ms 344 KB Output is correct
29 Correct 385 ms 344 KB Output is correct
30 Correct 372 ms 344 KB Output is correct
31 Correct 403 ms 436 KB Output is correct
32 Correct 410 ms 344 KB Output is correct
33 Correct 361 ms 344 KB Output is correct
34 Correct 363 ms 348 KB Output is correct
35 Correct 364 ms 348 KB Output is correct
36 Correct 368 ms 436 KB Output is correct
37 Correct 371 ms 348 KB Output is correct
38 Correct 312 ms 348 KB Output is correct
39 Correct 290 ms 436 KB Output is correct
40 Correct 173 ms 436 KB Output is correct
# 결과 실행 시간 메모리 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 348 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 508 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 274 ms 432 KB Output is correct
20 Correct 408 ms 344 KB Output is correct
21 Correct 393 ms 432 KB Output is correct
22 Correct 329 ms 436 KB Output is correct
23 Correct 446 ms 348 KB Output is correct
24 Correct 349 ms 344 KB Output is correct
25 Correct 313 ms 348 KB Output is correct
26 Correct 332 ms 348 KB Output is correct
27 Correct 354 ms 436 KB Output is correct
28 Correct 339 ms 436 KB Output is correct
29 Correct 380 ms 344 KB Output is correct
30 Correct 392 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 367 ms 348 KB Output is correct
33 Correct 375 ms 348 KB Output is correct
34 Correct 330 ms 348 KB Output is correct
35 Correct 354 ms 344 KB Output is correct
36 Correct 384 ms 344 KB Output is correct
37 Correct 338 ms 348 KB Output is correct
38 Correct 399 ms 432 KB Output is correct
39 Correct 382 ms 348 KB Output is correct
40 Correct 267 ms 344 KB Output is correct
41 Correct 295 ms 432 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 338 ms 436 KB Output is correct
44 Correct 385 ms 444 KB Output is correct
45 Correct 323 ms 344 KB Output is correct
46 Correct 423 ms 344 KB Output is correct
47 Correct 352 ms 344 KB Output is correct
48 Correct 361 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 393 ms 348 KB Output is correct
51 Correct 366 ms 348 KB Output is correct
52 Correct 381 ms 348 KB Output is correct
53 Correct 174 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 364 ms 432 KB Output is correct
56 Correct 361 ms 596 KB Output is correct
57 Correct 403 ms 432 KB Output is correct
58 Correct 426 ms 344 KB Output is correct
59 Correct 402 ms 436 KB Output is correct
60 Correct 338 ms 348 KB Output is correct
61 Correct 358 ms 436 KB Output is correct
62 Correct 380 ms 348 KB Output is correct
63 Correct 399 ms 344 KB Output is correct
64 Correct 403 ms 348 KB Output is correct
65 Correct 370 ms 348 KB Output is correct
66 Correct 373 ms 436 KB Output is correct
67 Correct 376 ms 344 KB Output is correct
68 Correct 385 ms 344 KB Output is correct
69 Correct 372 ms 344 KB Output is correct
70 Correct 403 ms 436 KB Output is correct
71 Correct 410 ms 344 KB Output is correct
72 Correct 361 ms 344 KB Output is correct
73 Correct 363 ms 348 KB Output is correct
74 Correct 364 ms 348 KB Output is correct
75 Correct 368 ms 436 KB Output is correct
76 Correct 371 ms 348 KB Output is correct
77 Correct 312 ms 348 KB Output is correct
78 Correct 290 ms 436 KB Output is correct
79 Correct 173 ms 436 KB Output is correct
80 Correct 651 ms 348 KB Output is correct
81 Correct 660 ms 348 KB Output is correct
82 Correct 478 ms 344 KB Output is correct
83 Correct 483 ms 348 KB Output is correct
84 Correct 538 ms 344 KB Output is correct
85 Correct 468 ms 348 KB Output is correct
86 Correct 489 ms 344 KB Output is correct
87 Correct 647 ms 348 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 734 ms 528 KB Output is correct
90 Correct 676 ms 596 KB Output is correct
91 Correct 652 ms 348 KB Output is correct
92 Correct 676 ms 528 KB Output is correct
93 Correct 665 ms 348 KB Output is correct
94 Correct 648 ms 596 KB Output is correct
95 Correct 662 ms 344 KB Output is correct
96 Correct 606 ms 344 KB Output is correct
97 Correct 585 ms 348 KB Output is correct
98 Correct 631 ms 344 KB Output is correct
99 Correct 584 ms 344 KB Output is correct
100 Correct 638 ms 344 KB Output is correct
101 Correct 564 ms 348 KB Output is correct
102 Correct 615 ms 524 KB Output is correct
103 Correct 610 ms 348 KB Output is correct
104 Correct 591 ms 524 KB Output is correct
105 Correct 603 ms 524 KB Output is correct
106 Correct 561 ms 344 KB Output is correct
107 Correct 594 ms 348 KB Output is correct
108 Correct 597 ms 348 KB Output is correct
109 Correct 628 ms 344 KB Output is correct
110 Correct 614 ms 344 KB Output is correct
111 Correct 419 ms 348 KB Output is correct
112 Correct 458 ms 348 KB Output is correct
113 Correct 427 ms 428 KB Output is correct
114 Correct 627 ms 532 KB Output is correct
115 Correct 654 ms 348 KB Output is correct
116 Correct 676 ms 344 KB Output is correct
# 결과 실행 시간 메모리 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 348 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 508 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 274 ms 432 KB Output is correct
20 Correct 408 ms 344 KB Output is correct
21 Correct 393 ms 432 KB Output is correct
22 Correct 329 ms 436 KB Output is correct
23 Correct 446 ms 348 KB Output is correct
24 Correct 349 ms 344 KB Output is correct
25 Correct 313 ms 348 KB Output is correct
26 Correct 332 ms 348 KB Output is correct
27 Correct 354 ms 436 KB Output is correct
28 Correct 339 ms 436 KB Output is correct
29 Correct 380 ms 344 KB Output is correct
30 Correct 392 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 367 ms 348 KB Output is correct
33 Correct 375 ms 348 KB Output is correct
34 Correct 330 ms 348 KB Output is correct
35 Correct 354 ms 344 KB Output is correct
36 Correct 384 ms 344 KB Output is correct
37 Correct 338 ms 348 KB Output is correct
38 Correct 399 ms 432 KB Output is correct
39 Correct 382 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 596 ms 4492 KB Output is correct
42 Correct 571 ms 4564 KB Output is correct
43 Correct 548 ms 4564 KB Output is correct
44 Correct 577 ms 4756 KB Output is correct
45 Correct 563 ms 4572 KB Output is correct
46 Correct 16 ms 3420 KB Output is correct
47 Correct 17 ms 3612 KB Output is correct
48 Correct 18 ms 3416 KB Output is correct
49 Correct 682 ms 4572 KB Output is correct
50 Correct 316 ms 4064 KB Output is correct
51 Correct 310 ms 4064 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 682 ms 4744 KB Output is correct
54 Correct 675 ms 4572 KB Output is correct
55 Correct 553 ms 4756 KB Output is correct
56 Correct 629 ms 4572 KB Output is correct
57 Correct 579 ms 4568 KB Output is correct
58 Correct 560 ms 4572 KB Output is correct
59 Correct 558 ms 4572 KB Output is correct
60 Correct 267 ms 344 KB Output is correct
61 Correct 295 ms 432 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 338 ms 436 KB Output is correct
64 Correct 385 ms 444 KB Output is correct
65 Correct 323 ms 344 KB Output is correct
66 Correct 423 ms 344 KB Output is correct
67 Correct 352 ms 344 KB Output is correct
68 Correct 361 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 393 ms 348 KB Output is correct
71 Correct 366 ms 348 KB Output is correct
72 Correct 381 ms 348 KB Output is correct
73 Correct 174 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 364 ms 432 KB Output is correct
76 Correct 361 ms 596 KB Output is correct
77 Correct 403 ms 432 KB Output is correct
78 Correct 426 ms 344 KB Output is correct
79 Correct 402 ms 436 KB Output is correct
80 Correct 338 ms 348 KB Output is correct
81 Correct 358 ms 436 KB Output is correct
82 Correct 380 ms 348 KB Output is correct
83 Correct 399 ms 344 KB Output is correct
84 Correct 403 ms 348 KB Output is correct
85 Correct 370 ms 348 KB Output is correct
86 Correct 373 ms 436 KB Output is correct
87 Correct 376 ms 344 KB Output is correct
88 Correct 385 ms 344 KB Output is correct
89 Correct 372 ms 344 KB Output is correct
90 Correct 403 ms 436 KB Output is correct
91 Correct 410 ms 344 KB Output is correct
92 Correct 361 ms 344 KB Output is correct
93 Correct 363 ms 348 KB Output is correct
94 Correct 364 ms 348 KB Output is correct
95 Correct 368 ms 436 KB Output is correct
96 Correct 371 ms 348 KB Output is correct
97 Correct 312 ms 348 KB Output is correct
98 Correct 290 ms 436 KB Output is correct
99 Correct 173 ms 436 KB Output is correct
100 Correct 651 ms 348 KB Output is correct
101 Correct 660 ms 348 KB Output is correct
102 Correct 478 ms 344 KB Output is correct
103 Correct 483 ms 348 KB Output is correct
104 Correct 538 ms 344 KB Output is correct
105 Correct 468 ms 348 KB Output is correct
106 Correct 489 ms 344 KB Output is correct
107 Correct 647 ms 348 KB Output is correct
108 Correct 0 ms 348 KB Output is correct
109 Correct 734 ms 528 KB Output is correct
110 Correct 676 ms 596 KB Output is correct
111 Correct 652 ms 348 KB Output is correct
112 Correct 676 ms 528 KB Output is correct
113 Correct 665 ms 348 KB Output is correct
114 Correct 648 ms 596 KB Output is correct
115 Correct 662 ms 344 KB Output is correct
116 Correct 606 ms 344 KB Output is correct
117 Correct 585 ms 348 KB Output is correct
118 Correct 631 ms 344 KB Output is correct
119 Correct 584 ms 344 KB Output is correct
120 Correct 638 ms 344 KB Output is correct
121 Correct 564 ms 348 KB Output is correct
122 Correct 615 ms 524 KB Output is correct
123 Correct 610 ms 348 KB Output is correct
124 Correct 591 ms 524 KB Output is correct
125 Correct 603 ms 524 KB Output is correct
126 Correct 561 ms 344 KB Output is correct
127 Correct 594 ms 348 KB Output is correct
128 Correct 597 ms 348 KB Output is correct
129 Correct 628 ms 344 KB Output is correct
130 Correct 614 ms 344 KB Output is correct
131 Correct 419 ms 348 KB Output is correct
132 Correct 458 ms 348 KB Output is correct
133 Correct 427 ms 428 KB Output is correct
134 Correct 627 ms 532 KB Output is correct
135 Correct 654 ms 348 KB Output is correct
136 Correct 676 ms 344 KB Output is correct
137 Correct 678 ms 4572 KB Output is correct
138 Correct 629 ms 4564 KB Output is correct
139 Correct 668 ms 4572 KB Output is correct
140 Correct 699 ms 4488 KB Output is correct
141 Correct 699 ms 4568 KB Output is correct
142 Correct 550 ms 856 KB Output is correct
143 Correct 556 ms 860 KB Output is correct
144 Correct 545 ms 860 KB Output is correct
145 Correct 556 ms 856 KB Output is correct
146 Correct 665 ms 856 KB Output is correct
147 Correct 627 ms 980 KB Output is correct
148 Correct 0 ms 344 KB Output is correct
149 Correct 661 ms 4756 KB Output is correct
150 Correct 728 ms 4500 KB Output is correct
151 Correct 622 ms 4568 KB Output is correct
152 Correct 720 ms 4572 KB Output is correct
153 Correct 685 ms 4572 KB Output is correct
154 Correct 618 ms 4756 KB Output is correct
155 Correct 674 ms 4568 KB Output is correct
156 Correct 667 ms 4316 KB Output is correct
157 Correct 636 ms 4316 KB Output is correct
158 Correct 656 ms 4312 KB Output is correct
159 Correct 647 ms 4316 KB Output is correct
160 Correct 636 ms 4316 KB Output is correct
161 Correct 676 ms 4312 KB Output is correct
162 Correct 666 ms 4312 KB Output is correct
163 Correct 684 ms 4312 KB Output is correct
164 Correct 651 ms 4316 KB Output is correct
165 Correct 607 ms 4316 KB Output is correct
166 Correct 632 ms 4056 KB Output is correct
167 Correct 648 ms 4312 KB Output is correct
168 Correct 654 ms 4312 KB Output is correct
169 Incorrect 599 ms 4060 KB Output isn't correct
170 Halted 0 ms 0 KB -