이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> v2i;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
int gcd(int a, int b) {
//cout << "gcd " << a << " " << b << "\n";
if (b > a) swap(a, b);
if (b == 0) return a;
if (b == 1) return 1;
if (a % b == 0) return b;
else return gcd(b, a % b);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vpi coords;
int xi, yi;
rep(i, n) {
cin >> xi >> yi;
coords.pb({ xi, yi });
}
if (n <= 2) {
cout << -1;
return 0;
}
if (n == 3) {
int a = abs(coords[0].first - coords[2].first) + abs(coords[0].second - coords[2].second);
int b = abs(coords[0].first - coords[2].first) + abs(coords[0].second - coords[2].second);
int c = abs(coords[1].first - coords[2].first) + abs(coords[1].second - coords[2].second);
cout << min(min(a + b, b + c), a+c);
}
int gx = abs(coords[0].first - coords[1].first);
int gy = abs(coords[0].second - coords[1].second);
for (int i = 1; i < n - 1; i++) {
if (abs(coords[i].first - coords[i + 1].first)!=0) gx = gcd(gx, abs(coords[i].first - coords[i + 1].first));
if (abs(coords[i].second - coords[i + 1].second)!=0) gy = gcd(gy, abs(coords[i].second - coords[i + 1].second));
}
cout << (ll)gx * gy;
return 0;
}
# | 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... |