結果
問題 | No.180 美しいWhitespace (2) |
ユーザー |
![]() |
提出日時 | 2016-09-22 21:44:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,792 bytes |
コンパイル時間 | 1,560 ms |
コンパイル使用メモリ | 170,056 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 13:17:52 |
合計ジャッジ時間 | 32,653 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 WA * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; namespace { typedef long double real; typedef long long ll; template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) { if (vs.empty()) return os << "[]"; auto i = vs.begin(); os << "[" << *i; for (++i; i != vs.end(); ++i) os << " " << *i; return os << "]"; } template<class T> istream& operator>>(istream& is, vector<T>& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } const ll INF = LLONG_MAX / 2LL; int N; vector<ll> A, B; void input() { cin >> N; A.resize(N); B.resize(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; } } ll C(ll x) { ll m = INF; ll M = 0; for (int i = 0; i < N; i++) { m = min(m, A[i] + B[i] * x); M = max(M, A[i] + B[i] * x); } //cout << x << " -> " << M - m << endl; return M - m; } void solve() { if (N == 1) { cout << 1 << endl; return; } ll len = C(1); ll t = 1; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (B[i] == B[j]) continue; ll x = - (A[i] - A[j]) / real(B[i] - B[j]); if (x <= 0) continue; ll y = floor(x); for (ll dy = -2; dy <= 2; dy++) { ll p = C(y + dy); if (len > p) { len = p; t = y + dy; } } } } cout << t << endl; } } int main() { input(); solve(); return 0; }