Submission #1045441

# Submission time Handle Problem Language Result Execution time Memory
1045441 2024-08-06T01:06:28 Z Darren0724 Portal (BOI24_portal) C++17
65 / 100
1286 ms 4824 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 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;
    }
    int times=0;
    shuffle(all(t),rnd);
    for(int i=0;i<sz&&times<=(2.5e7);i++){
        for(int j=i+1;j<sz&&times<=(2.5e7);j++){
            times++;
            solve(t[i],t[j]);
        }
    }
    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 1 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 1 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 1 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 1 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 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 827 ms 4572 KB Output is correct
3 Correct 798 ms 4572 KB Output is correct
4 Correct 778 ms 4572 KB Output is correct
5 Correct 813 ms 4572 KB Output is correct
6 Correct 855 ms 4488 KB Output is correct
7 Correct 16 ms 3420 KB Output is correct
8 Correct 16 ms 3416 KB Output is correct
9 Correct 16 ms 3604 KB Output is correct
10 Correct 1182 ms 4572 KB Output is correct
11 Correct 269 ms 4056 KB Output is correct
12 Correct 284 ms 4060 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1286 ms 4572 KB Output is correct
15 Correct 1197 ms 4568 KB Output is correct
16 Correct 796 ms 4568 KB Output is correct
17 Correct 1059 ms 4572 KB Output is correct
18 Correct 850 ms 4568 KB Output is correct
19 Correct 819 ms 4560 KB Output is correct
20 Correct 848 ms 4560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 460 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 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 460 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 96 ms 540 KB Output is correct
81 Correct 101 ms 344 KB Output is correct
82 Correct 15 ms 348 KB Output is correct
83 Correct 15 ms 508 KB Output is correct
84 Correct 18 ms 504 KB Output is correct
85 Correct 15 ms 348 KB Output is correct
86 Correct 16 ms 348 KB Output is correct
87 Correct 24 ms 348 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 98 ms 348 KB Output is correct
90 Correct 113 ms 348 KB Output is correct
91 Correct 110 ms 344 KB Output is correct
92 Correct 104 ms 528 KB Output is correct
93 Correct 102 ms 536 KB Output is correct
94 Correct 97 ms 348 KB Output is correct
95 Correct 103 ms 344 KB Output is correct
96 Correct 77 ms 528 KB Output is correct
97 Correct 69 ms 528 KB Output is correct
98 Correct 80 ms 348 KB Output is correct
99 Correct 73 ms 348 KB Output is correct
100 Correct 78 ms 540 KB Output is correct
101 Correct 61 ms 348 KB Output is correct
102 Correct 72 ms 348 KB Output is correct
103 Correct 71 ms 344 KB Output is correct
104 Correct 65 ms 344 KB Output is correct
105 Correct 71 ms 348 KB Output is correct
106 Correct 62 ms 348 KB Output is correct
107 Correct 66 ms 348 KB Output is correct
108 Correct 64 ms 348 KB Output is correct
109 Correct 78 ms 344 KB Output is correct
110 Correct 67 ms 344 KB Output is correct
111 Correct 0 ms 348 KB Output is correct
112 Correct 0 ms 348 KB Output is correct
113 Correct 0 ms 348 KB Output is correct
114 Correct 92 ms 348 KB Output is correct
115 Correct 98 ms 348 KB Output is correct
116 Correct 93 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 827 ms 4572 KB Output is correct
42 Correct 798 ms 4572 KB Output is correct
43 Correct 778 ms 4572 KB Output is correct
44 Correct 813 ms 4572 KB Output is correct
45 Correct 855 ms 4488 KB Output is correct
46 Correct 16 ms 3420 KB Output is correct
47 Correct 16 ms 3416 KB Output is correct
48 Correct 16 ms 3604 KB Output is correct
49 Correct 1182 ms 4572 KB Output is correct
50 Correct 269 ms 4056 KB Output is correct
51 Correct 284 ms 4060 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 1286 ms 4572 KB Output is correct
54 Correct 1197 ms 4568 KB Output is correct
55 Correct 796 ms 4568 KB Output is correct
56 Correct 1059 ms 4572 KB Output is correct
57 Correct 850 ms 4568 KB Output is correct
58 Correct 819 ms 4560 KB Output is correct
59 Correct 848 ms 4560 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 0 ms 344 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 0 ms 460 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 0 ms 348 KB Output is correct
81 Correct 1 ms 348 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 1 ms 344 KB Output is correct
86 Correct 1 ms 344 KB Output is correct
87 Correct 1 ms 348 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 0 ms 348 KB Output is correct
93 Correct 0 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 96 ms 540 KB Output is correct
101 Correct 101 ms 344 KB Output is correct
102 Correct 15 ms 348 KB Output is correct
103 Correct 15 ms 508 KB Output is correct
104 Correct 18 ms 504 KB Output is correct
105 Correct 15 ms 348 KB Output is correct
106 Correct 16 ms 348 KB Output is correct
107 Correct 24 ms 348 KB Output is correct
108 Correct 0 ms 348 KB Output is correct
109 Correct 98 ms 348 KB Output is correct
110 Correct 113 ms 348 KB Output is correct
111 Correct 110 ms 344 KB Output is correct
112 Correct 104 ms 528 KB Output is correct
113 Correct 102 ms 536 KB Output is correct
114 Correct 97 ms 348 KB Output is correct
115 Correct 103 ms 344 KB Output is correct
116 Correct 77 ms 528 KB Output is correct
117 Correct 69 ms 528 KB Output is correct
118 Correct 80 ms 348 KB Output is correct
119 Correct 73 ms 348 KB Output is correct
120 Correct 78 ms 540 KB Output is correct
121 Correct 61 ms 348 KB Output is correct
122 Correct 72 ms 348 KB Output is correct
123 Correct 71 ms 344 KB Output is correct
124 Correct 65 ms 344 KB Output is correct
125 Correct 71 ms 348 KB Output is correct
126 Correct 62 ms 348 KB Output is correct
127 Correct 66 ms 348 KB Output is correct
128 Correct 64 ms 348 KB Output is correct
129 Correct 78 ms 344 KB Output is correct
130 Correct 67 ms 344 KB Output is correct
131 Correct 0 ms 348 KB Output is correct
132 Correct 0 ms 348 KB Output is correct
133 Correct 0 ms 348 KB Output is correct
134 Correct 92 ms 348 KB Output is correct
135 Correct 98 ms 348 KB Output is correct
136 Correct 93 ms 344 KB Output is correct
137 Correct 1209 ms 4572 KB Output is correct
138 Correct 1070 ms 4568 KB Output is correct
139 Correct 1213 ms 4568 KB Output is correct
140 Correct 1250 ms 4568 KB Output is correct
141 Correct 1215 ms 4756 KB Output is correct
142 Correct 945 ms 856 KB Output is correct
143 Correct 941 ms 856 KB Output is correct
144 Correct 933 ms 1104 KB Output is correct
145 Correct 906 ms 996 KB Output is correct
146 Correct 1262 ms 860 KB Output is correct
147 Correct 1172 ms 984 KB Output is correct
148 Correct 1 ms 348 KB Output is correct
149 Correct 1227 ms 4760 KB Output is correct
150 Correct 1277 ms 4572 KB Output is correct
151 Correct 1097 ms 4824 KB Output is correct
152 Correct 1282 ms 4760 KB Output is correct
153 Correct 1276 ms 4760 KB Output is correct
154 Correct 1090 ms 4756 KB Output is correct
155 Correct 1205 ms 4640 KB Output is correct
156 Correct 1138 ms 4316 KB Output is correct
157 Correct 1107 ms 4316 KB Output is correct
158 Correct 1109 ms 4316 KB Output is correct
159 Correct 1120 ms 4316 KB Output is correct
160 Correct 1086 ms 4572 KB Output is correct
161 Correct 1158 ms 4312 KB Output is correct
162 Correct 1150 ms 4316 KB Output is correct
163 Correct 1200 ms 4352 KB Output is correct
164 Correct 1083 ms 4316 KB Output is correct
165 Correct 1042 ms 4312 KB Output is correct
166 Correct 1094 ms 4060 KB Output is correct
167 Correct 1116 ms 4312 KB Output is correct
168 Correct 1116 ms 4316 KB Output is correct
169 Incorrect 974 ms 4060 KB Output isn't correct
170 Halted 0 ms 0 KB -