제출 #1169732

#제출 시각아이디문제언어결과실행 시간메모리
1169732steveonalexPortal (BOI24_portal)C++20
1 / 100
52 ms2884 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));} ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ull mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} double rngesus_d(double l, double r){ double cur = rngesus(0, MASK(60) - 1); cur /= MASK(60) - 1; return l + cur * (r - l); } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 210; const int X = N * 2 + 1, Y = N * 2 + 2; int grid[X][Y]; pair<ll, ll> vt[N]; ll solve(){ int n; cin >> n; vector<pair<ll, ll>> portal(n); for(int i = 0; i < n; ++i) cin >> portal[i].first >> portal[i].second; if (n <= 2){ return -1; } sort(ALL(portal)); for(int i = 0; i + 1 < n; ++i){ vt[i] = make_pair(portal.back().first - portal[i].first, portal.back().second - portal[i].second); } vector<pair<int, int>> st; st.reserve(N * N); st.push_back(make_pair(N, N)); memset(grid, 63, sizeof grid); grid[N][N] = N; while(st.size()){ int x, y; tie(x, y) = st.back(); st.pop_back(); for(int i = 0; i < n-1; ++i){ pair<ll, ll> dih = vt[i]; for(int it = 0; it <= 1; ++it){ int u = x + dih.first, v = grid[x][y] + dih.second; if (min(u, v) < 0 || u >= X) continue; int _v = min(v, Y-1); if (minimize(grid[u][_v], v)) st.push_back(make_pair(u, _v)); dih = make_pair(-dih.first, -dih.second); } } } ll nearest_x = 0, nearest_y = 0; for(int j = N+1; j <= N*2+1; ++j){ if (grid[N][j] < 1e9) { nearest_y = j - N; break; } } for(int i = N+1; i <= N*2; ++i) { for(int j = 0; j <= N*2+1; ++j) if (grid[i][j] < 1e9) nearest_x = i - N; if (nearest_x != 0) break; } if (nearest_x * nearest_y == 0) return -1; ll ans = nearest_x * nearest_y; return ans; } int main(void){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); cout << solve() << "\n"; 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...