結果
問題 | No.5009 Draw A Convex Polygon |
ユーザー | wanui |
提出日時 | 2022-12-02 01:21:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 944 ms / 2,600 ms |
コード長 | 5,234 bytes |
コンパイル時間 | 3,047 ms |
実行使用メモリ | 39,236 KB |
スコア | 1,000,000 |
平均クエリ数 | 1000001.00 |
最終ジャッジ日時 | 2022-12-02 01:21:11 |
合計ジャッジ時間 | 5,649 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
ソースコード
#include <bits/stdc++.h> // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);} void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); } #define debug1(a) { cerr<<#a<<":"<<a<<endl; } #define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; } #define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; } #define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; } // clang-format on using pii = pair<int, int>; namespace rational { struct rational { int numer; // 分子 int denom; // 分母 double todouble() { return double(numer) / denom; } int floor() { return numer / denom; } int ceil() { return (numer + denom - 1) / denom; } pii topii() { return {numer, denom}; } }; int _gcd(int a, int b) { if (b == 0) { return a; } return _gcd(b, a % b); } rational _reduce(int n, int d) { if (d == 0) { // assert(false); if (n > 0) { return {1, 0}; } else if (n < 0) { return {-1, 0}; } else { return {0, 0}; } } else if (n == 0) { return {0, 1}; } else if (d < 0) { n = -n; d = -d; int g = _gcd(abs(n), d); return {n / g, d / g}; } else { int g = _gcd(abs(n), d); return {n / g, d / g}; } } rational operator-(const rational& x) { return rational{-x.numer, x.denom}; } rational inv(const rational& x) { if (x.numer < 0) { return rational{-x.denom, -x.numer}; } return rational{x.denom, x.numer}; } rational operator+(const rational& lhs, const rational& rhs) { return _reduce(lhs.numer * rhs.denom + rhs.numer * lhs.denom, lhs.denom * rhs.denom); } rational operator*(const rational& lhs, const rational& rhs) { return _reduce(lhs.numer * rhs.numer, lhs.denom * rhs.denom); } rational operator-(const rational& lhs, const rational& rhs) { return lhs + (-rhs); } rational operator/(const rational& lhs, const rational& rhs) { return lhs * inv(rhs); } int _sub_numer(const rational& lhs, const rational& rhs) { return lhs.numer * rhs.denom - rhs.numer * lhs.denom; } bool operator<(const rational& lhs, const rational& rhs) { return _sub_numer(lhs, rhs) < 0; } bool operator>(const rational& lhs, const rational& rhs) { return _sub_numer(lhs, rhs) > 0; } bool operator==(const rational& lhs, const rational& rhs) { return _sub_numer(lhs, rhs) == 0; } bool operator<=(const rational& lhs, const rational& rhs) { return _sub_numer(lhs, rhs) <= 0; } bool operator>=(const rational& lhs, const rational& rhs) { return _sub_numer(lhs, rhs) >= 0; } ostream& operator<<(ostream& os, const rational& a) { return os << a.numer << "/" << a.denom; } rational init(int n, int d) { return _reduce(n, d); } }; // namespace rational int main() { ioinit(); vector<rational::rational> rats; const int MX = 641; // const int MX = 3; for (int x = 1; x <= MX; x++) { for (int y = 1; y <= MX; y++) { if (max(x, y) == 577 && min(x, y) <= 177) continue; if (x == y) continue; auto rat = rational::init(y, x); rats.push_back(rat); } } sort(rats.rbegin(), rats.rend()); { vector<rational::rational> tmp; for (auto r : rats) { if (tmp.size() && tmp.back() == r) { continue; } tmp.push_back(r); } rats = tmp; } // const int BASEY = 80267797; // const int BASEX = 80126150; vector<pii> result; { pii cur = {1, 1}; vector<pii> points; for (auto rat : rats) { points.push_back(cur); pii d = rat.topii(); pii nxt = {cur.first + d.second, cur.second + d.first}; cur = nxt; } for (auto p : points) { result.push_back(p); } int BASEX = points.back().first + 1; reverse(points.begin(), points.end()); for (auto p : points) { pii q = {BASEX + BASEX - p.first, p.second}; result.push_back(q); } auto revrslt = result; reverse(revrslt.begin(), revrslt.end()); for (auto p : revrslt) { pii q = {p.first, -p.second}; result.push_back(q); } } reverse(result.begin(), result.end()); print(result.size()); for (auto r : result) { print(r.first, r.second); } cout.flush(); return 0; }