제출 #1052854

#제출 시각아이디문제언어결과실행 시간메모리
1052854pravcoderPortal (BOI24_portal)C++17
11 / 100
17 ms2776 KiB
#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 == -1) return a; 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; int ox, oy; bool lx = true, ly = true; rep(i, n) { cin >> xi >> yi; coords.pb({ xi, yi }); if (i == 0) { ox = xi; oy = yi; } else { if (ox != xi) { lx = false; } if (oy != yi) { ly = false; } } } if (n <= 2 || (ly || lx)) { cout << -1; return 0; } int gx = -1; int gy = -1; for (int i = 0; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...