# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994672 |
2024-06-08T03:30:46 Z |
salmon |
Portal (BOI24_portal) |
C++14 |
|
25 ms |
3280 KB |
#include <bits/stdc++.h>
using namespace std;
int N;
long long int x,y;
long long int b,d;
long long int b1,d1;
long long int h1,h2;
bool flag = true;
bool floog = true;
vector<pair<long long int,long long int>> v;
pair<long long int, long long int> gbcd(pair<long long int, long long int> ii1, pair<long long int, long long int> ii2){
if(ii1.first > ii2.first) swap(ii1,ii2);
if(ii1.first == 0) return ii2;
return gbcd({ii2.first % ii1.first, ii2.second - ii2.first / ii1.first * ii1.second }, ii1);
}
int main(){
long long int num = 0;
long long int fum = 0;
scanf(" %d",&N);
scanf(" %lld",&x);
scanf(" %lld",&y);
b = 0;
d = 0;
for(int i = 0; i < N - 1; i++){
scanf(" %lld",&h1);
scanf(" %lld",&h2);
h1 -= x;
h2 -= y;
if(h1 == 0 && h2 == 0) continue;
flag &= (h1==0);
floog &= (h2==0);
if(h1 != 0){
h2 *= (h1)/abs(h1);
h1 = abs(h1);
pair<long long int, long long int> ii = make_pair(b,d);
ii = gbcd(ii,{h1,h2});
b = ii.first;
d = ii.second;
assert (d <= 1e15);
printf("%lld\n",d);
}
v.push_back({h1,h2});
}
if(flag || floog){
printf("%d",-1);
return 0;
}
for(pair<long long int,long long int> ii : v){
h1 = ii.first;
h2 = ii.second;
if(h1 != 0){
h2 *= (h1)/abs(h1);
h1 = abs(h1);
long long int c = __gcd(h1,b);
num = __gcd((__int128)num, (__int128)b / c * h2 - (__int128)h1 / c * d);
}
else{
num = __gcd(num, h2);
}
fum = __gcd(fum, h1);
}
//printf("%lld\n",num);
if(fum == 0 || num == 0) printf("%d",-1);
else{
printf("%lld",abs(num * fum));
}
}
/*
5
0 0
2 1000000
1000007 1000005
1000003 1000005
1000007 1000001
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf(" %d",&N);
| ~~~~~^~~~~~~~~~
Main.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf(" %lld",&x);
| ~~~~~^~~~~~~~~~~~
Main.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf(" %lld",&y);
| ~~~~~^~~~~~~~~~~~
Main.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf(" %lld",&h1);
| ~~~~~^~~~~~~~~~~~~
Main.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | scanf(" %lld",&h2);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
25 ms |
3280 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |