結果
問題 | No.3008 ワンオペ警備員 |
ユーザー |
👑 |
提出日時 | 2025-01-17 21:56:37 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 4,418 bytes |
コンパイル時間 | 1,525 ms |
コンパイル使用メモリ | 107,764 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-17 21:56:46 |
合計ジャッジ時間 | 2,656 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 37 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:119:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 119 | scanf("%lld%lld", &P[u].x, &P[u].y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") inline int sig(Int r) { return (r < 0) ? -1 : (r > 0) ? +1 : 0; } inline Int sq(Int r) { return r * r; } struct Pt { Int x, y; Pt() : x(0), y(0) {} Pt(Int x_, Int y_) : x(x_), y(y_) {} Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); } Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); } Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); } Pt operator+() const { return Pt(+x, +y); } Pt operator-() const { return Pt(-x, -y); } Pt operator*(const Int &k) const { return Pt(x * k, y * k); } Pt operator/(const Int &k) const { return Pt(x / k, y / k); } friend Pt operator*(const Int &k, const Pt &a) { return Pt(k * a.x, k * a.y); } Pt &operator+=(const Pt &a) { x += a.x; y += a.y; return *this; } Pt &operator-=(const Pt &a) { x -= a.x; y -= a.y; return *this; } Pt &operator*=(const Pt &a) { return *this = *this * a; } Pt &operator*=(const Int &k) { x *= k; y *= k; return *this; } Pt &operator/=(const Int &k) { x /= k; y /= k; return *this; } Int abs2() const { return x * x + y * y; } Int dot(const Pt &a) const { return x * a.x + y * a.y; } Int det(const Pt &a) const { return x * a.y - y * a.x; } bool operator==(const Pt &a) const { return (x == a.x && y == a.y); } bool operator!=(const Pt &a) const { return !(x == a.x && y == a.y); } bool operator<(const Pt &a) const { return ((x != a.x) ? (x < a.x) : (y < a.y)); } friend ostream &operator<<(ostream &os, const Pt &a) { os << "(" << a.x << ", " << a.y << ")"; return os; } }; inline Int tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); } bool iSSStrict(const Pt &a, const Pt &b, const Pt &c, const Pt &d) { return (sig(tri(a, b, c)) * sig(tri(a, b, d)) < 0 && sig(tri(c, d, a)) * sig(tri(c, d, b)) < 0); } bool check(const Pt &a, const Pt &b, const Pt &c) { int s = sig((b - a).det(c - a)); if (s != 0) return false; if (sig((b - a).dot(c - a)) <= 0) return false; // c-a-b if (sig((a - b).dot(c - b)) <= 0) return false; // a-b-c return true; } int N; vector<Pt> P; int mod(int u) { return ((u %= N) < 0) ? (u + N) : u; } int solve() { for (int u = 0; u < N; ++u) for (int v = u + 1; v < N; ++v) { const Pt a = P[u], b = P[mod(u + 1)]; const Pt c = P[v], d = P[mod(v + 1)]; if (check(a, b, c)) return 0; if (check(a, b, d)) return 0; if (check(c, d, a)) return 0; if (check(c, d, b)) return 0; if (iSSStrict(a, b, c, d)) return 0; } for (int u = 0; u < N; ++u) { if (tri(P[u], P[mod(u + 1)], P[mod(u + 2)]) == 0) return 0; } __int128 area = 0; for (int u = 0; u < N; ++u) area += P[u].det(P[mod(u + 1)]); if (area < 0) reverse(P.begin(), P.end()); for (int u = 0; u < N; ++u) { bool ok = true; for (int i = 1; i <= N - 2; ++i) { const int v = mod(u + i); const int w = mod(u + i + 1); ok = ok && (tri(P[u], P[v], P[w]) >= 0); } if (ok) return 1; } return -1; } int main() { for (; ~scanf("%d", &N); ) { P.resize(N); for (int u = 0; u < N; ++u) { scanf("%lld%lld", &P[u].x, &P[u].y); } const int ans = solve(); printf("%d\n", ans); } return 0; }