結果
| 問題 |
No.2594 Mix shake!!
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2023-11-29 01:14:12 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 2,370 bytes |
| コンパイル時間 | 8,035 ms |
| コンパイル使用メモリ | 398,680 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-27 09:46:28 |
| 合計ジャッジ時間 | 8,929 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 85 |
ソースコード
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using Rational = boost::multiprecision::cpp_rational;
vector<pair<Rational, Rational>> to_slope(const vector<tuple<Rational, Rational, Rational, int>> &AB) {
Rational x(0), y(0);
vector<pair<Rational, Rational>> ret;
for (auto [_, a, b, i] : AB) {
x += a;
y += b;
ret.emplace_back(x, y);
}
return ret;
}
bool solve() {
int N;
cin >> N;
vector<Rational> A(N), B(N), C(N), D(N);
for (auto &x : A) cin >> x;
for (auto &x : B) cin >> x;
for (auto &x : C) cin >> x;
for (auto &x : D) cin >> x;
vector<tuple<Rational, Rational, Rational, int>> AB, CD;
for (int i = 0; i < N; ++i) {
AB.emplace_back(B.at(i) / A.at(i), A.at(i), B.at(i), i);
CD.emplace_back(D.at(i) / C.at(i), C.at(i), D.at(i), i);
}
sort(AB.begin(), AB.end());
sort(CD.begin(), CD.end());
const auto lb_xys = to_slope(AB);
const auto ub_xys = to_slope(CD);
{
Rational x0(0), y0(0);
for (int i = 0; i < (int)lb_xys.size(); ++i) {
auto [x1, y1] = lb_xys.at(i);
for (auto [x, y] : ub_xys) {
if ((x1 - x0) * (y - y0) - (y1 - y0) * (x - x0) < 0) return false;
}
x0 = x1, y0 = y1;
}
}
{
bool same = true;
for (int i = 0; i < N; ++i) same &= get<3>(AB.at(i)) == get<3>(CD.at(i));
if (same) return true;
}
Rational vx(0), vy(0);
for (int i = 0; i + 1 < N; ++i) {
// cerr << i << " " << vx << " " << vy << endl;
const auto &[px, py] = ub_xys.at(i);
if (px <= vx) return true;
// y = a1 x + b1
const Rational a1 = (py - vy) / (px - vx);
const Rational b1 = vy - a1 * vx;
// y = a2 x + b2
const auto &[ax, ay] = lb_xys.at(i);
const auto &[bx, by] = lb_xys.at(i + 1);
const Rational a2 = (by - ay) / (bx - ax);
const Rational b2 = ay - a2 * ax;
if (a1 >= a2) return true;
vx = (b2 - b1) / (a1 - a2);
vy = a1 * vx + b1;
if (vx >= bx) return true;
}
return false;
}
int main() {
cin.tie(nullptr);
cin.sync_with_stdio(false);
cout << (solve() ? "Yes" : "No") << '\n';
}
hitonanode