Submission #1045457

# Submission time Handle Problem Language Result Execution time Memory
1045457 2024-08-06T01:20:03 Z Darren0724 Portal (BOI24_portal) C++17
65 / 100
1547 ms 2692 KB
#pragma GCC optimize("Ofast","O3","unroll-loops")
#pragma GCC target("avx","avx2")
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll 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=2e9;
const int mod=1e9+7;
const int N=200005;
const int K=20;
const int C=2000005;
 
ll gcd(ll a,ll 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;
    }
    ll ans=-1;
    auto solve=[&](int i,int j)->void {
        int r1=v[j].y/gcd(v[i].y,v[j].y);
        ll t=1ll*v[i].y*r1;
        int t1=t/v[j].y;
        ll x1=abs(1ll*v[i].x*r1-1ll*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<25000000;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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 344 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 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 470 ms 348 KB Output is correct
20 Correct 746 ms 348 KB Output is correct
21 Correct 762 ms 348 KB Output is correct
22 Correct 678 ms 344 KB Output is correct
23 Correct 895 ms 432 KB Output is correct
24 Correct 677 ms 444 KB Output is correct
25 Correct 580 ms 432 KB Output is correct
26 Correct 633 ms 348 KB Output is correct
27 Correct 608 ms 348 KB Output is correct
28 Correct 658 ms 428 KB Output is correct
29 Correct 712 ms 444 KB Output is correct
30 Correct 787 ms 436 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 715 ms 348 KB Output is correct
33 Correct 753 ms 428 KB Output is correct
34 Correct 647 ms 432 KB Output is correct
35 Correct 754 ms 348 KB Output is correct
36 Correct 765 ms 432 KB Output is correct
37 Correct 660 ms 432 KB Output is correct
38 Correct 807 ms 432 KB Output is correct
39 Correct 746 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1207 ms 2680 KB Output is correct
3 Correct 1202 ms 2528 KB Output is correct
4 Correct 1165 ms 2528 KB Output is correct
5 Correct 1166 ms 2684 KB Output is correct
6 Correct 1298 ms 2520 KB Output is correct
7 Correct 16 ms 1880 KB Output is correct
8 Correct 16 ms 1884 KB Output is correct
9 Correct 16 ms 2036 KB Output is correct
10 Correct 1482 ms 2524 KB Output is correct
11 Correct 491 ms 2516 KB Output is correct
12 Correct 503 ms 2296 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1501 ms 2412 KB Output is correct
15 Correct 1524 ms 2416 KB Output is correct
16 Correct 1267 ms 2528 KB Output is correct
17 Correct 1393 ms 2688 KB Output is correct
18 Correct 1229 ms 2528 KB Output is correct
19 Correct 1164 ms 2416 KB Output is correct
20 Correct 1211 ms 2684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 472 ms 436 KB Output is correct
2 Correct 503 ms 436 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 697 ms 452 KB Output is correct
5 Correct 816 ms 432 KB Output is correct
6 Correct 624 ms 348 KB Output is correct
7 Correct 869 ms 436 KB Output is correct
8 Correct 694 ms 344 KB Output is correct
9 Correct 741 ms 432 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 768 ms 348 KB Output is correct
12 Correct 741 ms 432 KB Output is correct
13 Correct 775 ms 432 KB Output is correct
14 Correct 288 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 724 ms 436 KB Output is correct
17 Correct 730 ms 348 KB Output is correct
18 Correct 788 ms 440 KB Output is correct
19 Correct 867 ms 436 KB Output is correct
20 Correct 816 ms 432 KB Output is correct
21 Correct 656 ms 344 KB Output is correct
22 Correct 707 ms 440 KB Output is correct
23 Correct 854 ms 432 KB Output is correct
24 Correct 847 ms 436 KB Output is correct
25 Correct 748 ms 436 KB Output is correct
26 Correct 735 ms 344 KB Output is correct
27 Correct 738 ms 348 KB Output is correct
28 Correct 751 ms 432 KB Output is correct
29 Correct 782 ms 344 KB Output is correct
30 Correct 752 ms 436 KB Output is correct
31 Correct 763 ms 348 KB Output is correct
32 Correct 783 ms 436 KB Output is correct
33 Correct 754 ms 348 KB Output is correct
34 Correct 758 ms 348 KB Output is correct
35 Correct 747 ms 344 KB Output is correct
36 Correct 750 ms 348 KB Output is correct
37 Correct 749 ms 448 KB Output is correct
38 Correct 627 ms 428 KB Output is correct
39 Correct 540 ms 348 KB Output is correct
40 Correct 287 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 470 ms 348 KB Output is correct
20 Correct 746 ms 348 KB Output is correct
21 Correct 762 ms 348 KB Output is correct
22 Correct 678 ms 344 KB Output is correct
23 Correct 895 ms 432 KB Output is correct
24 Correct 677 ms 444 KB Output is correct
25 Correct 580 ms 432 KB Output is correct
26 Correct 633 ms 348 KB Output is correct
27 Correct 608 ms 348 KB Output is correct
28 Correct 658 ms 428 KB Output is correct
29 Correct 712 ms 444 KB Output is correct
30 Correct 787 ms 436 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 715 ms 348 KB Output is correct
33 Correct 753 ms 428 KB Output is correct
34 Correct 647 ms 432 KB Output is correct
35 Correct 754 ms 348 KB Output is correct
36 Correct 765 ms 432 KB Output is correct
37 Correct 660 ms 432 KB Output is correct
38 Correct 807 ms 432 KB Output is correct
39 Correct 746 ms 348 KB Output is correct
40 Correct 472 ms 436 KB Output is correct
41 Correct 503 ms 436 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 697 ms 452 KB Output is correct
44 Correct 816 ms 432 KB Output is correct
45 Correct 624 ms 348 KB Output is correct
46 Correct 869 ms 436 KB Output is correct
47 Correct 694 ms 344 KB Output is correct
48 Correct 741 ms 432 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 768 ms 348 KB Output is correct
51 Correct 741 ms 432 KB Output is correct
52 Correct 775 ms 432 KB Output is correct
53 Correct 288 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 724 ms 436 KB Output is correct
56 Correct 730 ms 348 KB Output is correct
57 Correct 788 ms 440 KB Output is correct
58 Correct 867 ms 436 KB Output is correct
59 Correct 816 ms 432 KB Output is correct
60 Correct 656 ms 344 KB Output is correct
61 Correct 707 ms 440 KB Output is correct
62 Correct 854 ms 432 KB Output is correct
63 Correct 847 ms 436 KB Output is correct
64 Correct 748 ms 436 KB Output is correct
65 Correct 735 ms 344 KB Output is correct
66 Correct 738 ms 348 KB Output is correct
67 Correct 751 ms 432 KB Output is correct
68 Correct 782 ms 344 KB Output is correct
69 Correct 752 ms 436 KB Output is correct
70 Correct 763 ms 348 KB Output is correct
71 Correct 783 ms 436 KB Output is correct
72 Correct 754 ms 348 KB Output is correct
73 Correct 758 ms 348 KB Output is correct
74 Correct 747 ms 344 KB Output is correct
75 Correct 750 ms 348 KB Output is correct
76 Correct 749 ms 448 KB Output is correct
77 Correct 627 ms 428 KB Output is correct
78 Correct 540 ms 348 KB Output is correct
79 Correct 287 ms 436 KB Output is correct
80 Correct 1343 ms 480 KB Output is correct
81 Correct 1421 ms 600 KB Output is correct
82 Correct 947 ms 344 KB Output is correct
83 Correct 1004 ms 460 KB Output is correct
84 Correct 1122 ms 456 KB Output is correct
85 Correct 947 ms 460 KB Output is correct
86 Correct 982 ms 464 KB Output is correct
87 Correct 1329 ms 460 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 1348 ms 480 KB Output is correct
90 Correct 1462 ms 348 KB Output is correct
91 Correct 1385 ms 484 KB Output is correct
92 Correct 1547 ms 600 KB Output is correct
93 Correct 1413 ms 480 KB Output is correct
94 Correct 1354 ms 480 KB Output is correct
95 Correct 1379 ms 592 KB Output is correct
96 Correct 1280 ms 484 KB Output is correct
97 Correct 1208 ms 484 KB Output is correct
98 Correct 1338 ms 484 KB Output is correct
99 Correct 1243 ms 600 KB Output is correct
100 Correct 1296 ms 348 KB Output is correct
101 Correct 1186 ms 476 KB Output is correct
102 Correct 1214 ms 484 KB Output is correct
103 Correct 1278 ms 596 KB Output is correct
104 Correct 1191 ms 480 KB Output is correct
105 Correct 1239 ms 480 KB Output is correct
106 Correct 1177 ms 476 KB Output is correct
107 Correct 1226 ms 480 KB Output is correct
108 Correct 1226 ms 344 KB Output is correct
109 Correct 1279 ms 484 KB Output is correct
110 Correct 1263 ms 480 KB Output is correct
111 Correct 835 ms 348 KB Output is correct
112 Correct 931 ms 448 KB Output is correct
113 Correct 871 ms 432 KB Output is correct
114 Correct 1336 ms 484 KB Output is correct
115 Correct 1353 ms 344 KB Output is correct
116 Correct 1318 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 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 470 ms 348 KB Output is correct
20 Correct 746 ms 348 KB Output is correct
21 Correct 762 ms 348 KB Output is correct
22 Correct 678 ms 344 KB Output is correct
23 Correct 895 ms 432 KB Output is correct
24 Correct 677 ms 444 KB Output is correct
25 Correct 580 ms 432 KB Output is correct
26 Correct 633 ms 348 KB Output is correct
27 Correct 608 ms 348 KB Output is correct
28 Correct 658 ms 428 KB Output is correct
29 Correct 712 ms 444 KB Output is correct
30 Correct 787 ms 436 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 715 ms 348 KB Output is correct
33 Correct 753 ms 428 KB Output is correct
34 Correct 647 ms 432 KB Output is correct
35 Correct 754 ms 348 KB Output is correct
36 Correct 765 ms 432 KB Output is correct
37 Correct 660 ms 432 KB Output is correct
38 Correct 807 ms 432 KB Output is correct
39 Correct 746 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 1207 ms 2680 KB Output is correct
42 Correct 1202 ms 2528 KB Output is correct
43 Correct 1165 ms 2528 KB Output is correct
44 Correct 1166 ms 2684 KB Output is correct
45 Correct 1298 ms 2520 KB Output is correct
46 Correct 16 ms 1880 KB Output is correct
47 Correct 16 ms 1884 KB Output is correct
48 Correct 16 ms 2036 KB Output is correct
49 Correct 1482 ms 2524 KB Output is correct
50 Correct 491 ms 2516 KB Output is correct
51 Correct 503 ms 2296 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 1501 ms 2412 KB Output is correct
54 Correct 1524 ms 2416 KB Output is correct
55 Correct 1267 ms 2528 KB Output is correct
56 Correct 1393 ms 2688 KB Output is correct
57 Correct 1229 ms 2528 KB Output is correct
58 Correct 1164 ms 2416 KB Output is correct
59 Correct 1211 ms 2684 KB Output is correct
60 Correct 472 ms 436 KB Output is correct
61 Correct 503 ms 436 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 697 ms 452 KB Output is correct
64 Correct 816 ms 432 KB Output is correct
65 Correct 624 ms 348 KB Output is correct
66 Correct 869 ms 436 KB Output is correct
67 Correct 694 ms 344 KB Output is correct
68 Correct 741 ms 432 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 768 ms 348 KB Output is correct
71 Correct 741 ms 432 KB Output is correct
72 Correct 775 ms 432 KB Output is correct
73 Correct 288 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 724 ms 436 KB Output is correct
76 Correct 730 ms 348 KB Output is correct
77 Correct 788 ms 440 KB Output is correct
78 Correct 867 ms 436 KB Output is correct
79 Correct 816 ms 432 KB Output is correct
80 Correct 656 ms 344 KB Output is correct
81 Correct 707 ms 440 KB Output is correct
82 Correct 854 ms 432 KB Output is correct
83 Correct 847 ms 436 KB Output is correct
84 Correct 748 ms 436 KB Output is correct
85 Correct 735 ms 344 KB Output is correct
86 Correct 738 ms 348 KB Output is correct
87 Correct 751 ms 432 KB Output is correct
88 Correct 782 ms 344 KB Output is correct
89 Correct 752 ms 436 KB Output is correct
90 Correct 763 ms 348 KB Output is correct
91 Correct 783 ms 436 KB Output is correct
92 Correct 754 ms 348 KB Output is correct
93 Correct 758 ms 348 KB Output is correct
94 Correct 747 ms 344 KB Output is correct
95 Correct 750 ms 348 KB Output is correct
96 Correct 749 ms 448 KB Output is correct
97 Correct 627 ms 428 KB Output is correct
98 Correct 540 ms 348 KB Output is correct
99 Correct 287 ms 436 KB Output is correct
100 Correct 1343 ms 480 KB Output is correct
101 Correct 1421 ms 600 KB Output is correct
102 Correct 947 ms 344 KB Output is correct
103 Correct 1004 ms 460 KB Output is correct
104 Correct 1122 ms 456 KB Output is correct
105 Correct 947 ms 460 KB Output is correct
106 Correct 982 ms 464 KB Output is correct
107 Correct 1329 ms 460 KB Output is correct
108 Correct 0 ms 348 KB Output is correct
109 Correct 1348 ms 480 KB Output is correct
110 Correct 1462 ms 348 KB Output is correct
111 Correct 1385 ms 484 KB Output is correct
112 Correct 1547 ms 600 KB Output is correct
113 Correct 1413 ms 480 KB Output is correct
114 Correct 1354 ms 480 KB Output is correct
115 Correct 1379 ms 592 KB Output is correct
116 Correct 1280 ms 484 KB Output is correct
117 Correct 1208 ms 484 KB Output is correct
118 Correct 1338 ms 484 KB Output is correct
119 Correct 1243 ms 600 KB Output is correct
120 Correct 1296 ms 348 KB Output is correct
121 Correct 1186 ms 476 KB Output is correct
122 Correct 1214 ms 484 KB Output is correct
123 Correct 1278 ms 596 KB Output is correct
124 Correct 1191 ms 480 KB Output is correct
125 Correct 1239 ms 480 KB Output is correct
126 Correct 1177 ms 476 KB Output is correct
127 Correct 1226 ms 480 KB Output is correct
128 Correct 1226 ms 344 KB Output is correct
129 Correct 1279 ms 484 KB Output is correct
130 Correct 1263 ms 480 KB Output is correct
131 Correct 835 ms 348 KB Output is correct
132 Correct 931 ms 448 KB Output is correct
133 Correct 871 ms 432 KB Output is correct
134 Correct 1336 ms 484 KB Output is correct
135 Correct 1353 ms 344 KB Output is correct
136 Correct 1318 ms 480 KB Output is correct
137 Correct 1546 ms 2528 KB Output is correct
138 Correct 1347 ms 2524 KB Output is correct
139 Correct 1493 ms 2688 KB Output is correct
140 Correct 1498 ms 2528 KB Output is correct
141 Correct 1438 ms 2528 KB Output is correct
142 Correct 1149 ms 704 KB Output is correct
143 Correct 1130 ms 600 KB Output is correct
144 Correct 1143 ms 700 KB Output is correct
145 Correct 1143 ms 700 KB Output is correct
146 Correct 1389 ms 848 KB Output is correct
147 Correct 1345 ms 704 KB Output is correct
148 Correct 0 ms 344 KB Output is correct
149 Correct 1456 ms 2692 KB Output is correct
150 Correct 1519 ms 2692 KB Output is correct
151 Correct 1314 ms 2528 KB Output is correct
152 Correct 1508 ms 2524 KB Output is correct
153 Correct 1496 ms 2524 KB Output is correct
154 Correct 1339 ms 2528 KB Output is correct
155 Correct 1464 ms 2524 KB Output is correct
156 Correct 1419 ms 2544 KB Output is correct
157 Correct 1388 ms 2528 KB Output is correct
158 Correct 1371 ms 2524 KB Output is correct
159 Correct 1390 ms 2268 KB Output is correct
160 Correct 1397 ms 2276 KB Output is correct
161 Correct 1441 ms 2528 KB Output is correct
162 Correct 1444 ms 2516 KB Output is correct
163 Correct 1418 ms 2492 KB Output is correct
164 Correct 1352 ms 2488 KB Output is correct
165 Correct 1265 ms 2268 KB Output is correct
166 Correct 1376 ms 2272 KB Output is correct
167 Correct 1366 ms 2528 KB Output is correct
168 Correct 1401 ms 2272 KB Output is correct
169 Incorrect 1236 ms 2272 KB Output isn't correct
170 Halted 0 ms 0 KB -