이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define F first
#define S second
using namespace std;
vector<pll> point,vc;
ll n;
pll fd(pll a){
return max(a,{-a.F,-a.S});
}
void _gcd(pll &a,pll &b){
if(a.F==0||b.F==0)return;
if(a.F<b.F)swap(a,b);
ll g=a.F/b.F;
a.F-=b.F*g;
a.S-=b.S*g;
_gcd(b,a);
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=0;i<n;i++){
ll x,y;
cin>>x>>y;
point.push_back({x,y});
}
for(int i=1;i<n;i++){
vc.push_back(fd({point[i].F-point[0].F,point[i].S-point[0].S}));
}
pll now={0,0};
vector<ll> s;
for(int i=0;i<n-1;i++){
if(vc[i].F==0){
s.push_back(vc[i].S);
}else{
if(now==make_pair(0ll,0ll)){
now=vc[i];
}else{
_gcd(now,vc[i]);
if(now.F==0)swap(now,vc[i]);
s.push_back(vc[i].S);
}
}
}
ll sg=0;
for(int i=0;i<s.size();i++){
if(s[i]!=0){
if(sg==0)sg=abs(s[i]);
else sg=gcd(sg,abs(s[i]));
}
}
if(now.F==0||sg==0){
cout<<"-1\n";
}else{
cout<<now.F*sg<<"\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |