답안 #140340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
140340 2019-08-02T14:59:23 Z egorlifar Printed Circuit Board (CEOI12_circuit) C++17
20 / 100
100 ms 31224 KB
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { x = (x > y ? y: x);}
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { x = (x < y ? y: x);}
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 200228;


struct point
{
    int x, y;
    int id;
    point(){}
    point(int _x, int _y) {
        x = _x;
        y = _y;
    }
};


bool good[MAXN];


point operator +(const point &a, const point &b) {
    return point(a.x + b.x, a.y + b.y);
}


point operator -(const point &a, const point &b) {
    return point(a.x - b.x, a.y - b.y);
}


long long dist(const point &a, const point &b) {
    return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y);
}


long long vec(const point &a, const point &b) {
    return 1LL * a.x * b.y - 1LL * a.y * b.x;
}


bool operator <(const point &a, const point &b) {
    return dist(a, point(0, 0)) < dist(b, point(0, 0)) || (dist(a, point(0, 0)) == dist(b, point(0, 0))  && mp(a.x, a.y) < mp(b.x, b.y));
}

int n;
point p[MAXN];
point g;


bool comp(const point &a, const point &b) {
    long long s = vec(a, b);
    if (s == 0) {
        return dist(a, point(0, 0)) < dist(b, point(0, 0));
    }
    return s > 0;
}


bool operator ==(const point &a, const point &b) {
    return a.x == b.x && a.y == b.y;
}


bool intersect(point a, point b, point c) {
    if (c == a || c == b) {
        return false;
    }
    long long s = vec(a, c);
    long long s1 = vec(c, b);
    if (s == 0 || s1 == 0) {
        return true;
    }
    if (s > 0 && s1 < 0) {
        return false;
    }
    if (s < 0 && s1 > 0) {
        return false;
    }
    s = vec(c - a, b - a);
    s1 = vec(b - a, point(0, 0) - a);
    if (s > 0 && s1 < 0) {
        return false;
    }
    if (s < 0 && s1 > 0) {
        return false;
    }
    return true;
}



set<pair<point, pair<point, point> > >  s;
point q[MAXN];
int where[MAXN];
vector<pair<point, point> >add[MAXN], del[MAXN]; 


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME); 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].x >> p[i].y;
        p[i].id = i + 1;
        q[i] = p[i];
    }
    sort(p, p + n, comp);
    for (int i = 0; i < n; i++) {
        where[p[i].id] = i;
    }
    for (int i = 0; i < n; i++) {
        int j = where[i + 1];
        int k = where[(i + 1) % n + 1];
        point a = q[i];
        point b = q[(i + 1) % n];
        if (j > k) {
            swap(j, k);
            swap(a, b);
        }
        add[j].pb({a, b});
        del[k].pb({a, b});
    }
    vector<int> f;
    for (int i = 0; i < n; i++) {
        bool bad = false;
        for (auto x: s) {
            if (intersect(s.begin()->second.first, s.begin()->second.second, p[i])) {
                bad = true;
                break;
            }
        }
        if (!s.empty() && intersect(s.begin()->second.first, s.begin()->second.second, p[i])) {
            bad = true;
        }
        for (auto x: add[i]) {
            point d = x.first + x.second;
            s.insert({d, x});
        }
        for (auto x: s) {
            if (intersect(s.begin()->second.first, s.begin()->second.second, p[i])) {
                bad = true;
                break;
            }
        }
        if (intersect(s.begin()->second.first, s.begin()->second.second, p[i])) {
            bad = true;
        }
        for (auto x: del[i]) {
            point d = x.first + x.second;
            s.erase({d, x});
        }
        for (auto x: s) {
            if (intersect(s.begin()->second.first, s.begin()->second.second, p[i])) {
                bad = true;
                break;
            }
        }
        if (!s.empty() && intersect(s.begin()->second.first, s.begin()->second.second, p[i])) {
            bad = true;
        }
        if (!bad) {
            good[p[i].id] = true;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (good[i]) {
            f.pb(i);
        }
    }
    cout << sz(f) << '\n';
    for (auto x: f) {
        cout << x << ' ';
    }
    cout << endl;
    return 0; 
}


Compilation message

circuit.cpp: In function 'int main()':
circuit.cpp:183:19: warning: variable 'x' set but not used [-Wunused-but-set-variable]
         for (auto x: s) {
                   ^
circuit.cpp:196:19: warning: variable 'x' set but not used [-Wunused-but-set-variable]
         for (auto x: s) {
                   ^
circuit.cpp:209:19: warning: variable 'x' set but not used [-Wunused-but-set-variable]
         for (auto x: s) {
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 9848 KB Output is correct
2 Incorrect 11 ms 9848 KB Output isn't correct
3 Correct 13 ms 10108 KB Output is correct
4 Correct 14 ms 10232 KB Output is correct
5 Incorrect 24 ms 11044 KB Output isn't correct
6 Incorrect 24 ms 11000 KB Output isn't correct
7 Incorrect 43 ms 12152 KB Output isn't correct
8 Incorrect 22 ms 10744 KB Output isn't correct
9 Execution timed out 434 ms 11088 KB Time limit exceeded
10 Incorrect 28 ms 11000 KB Output isn't correct
11 Incorrect 26 ms 11128 KB Output isn't correct
12 Incorrect 27 ms 11640 KB Output isn't correct
13 Incorrect 93 ms 13356 KB Output isn't correct
14 Correct 45 ms 13560 KB Output is correct
15 Incorrect 69 ms 14456 KB Output isn't correct
16 Execution timed out 106 ms 18936 KB Time limit exceeded
17 Execution timed out 328 ms 20496 KB Time limit exceeded
18 Execution timed out 187 ms 28024 KB Time limit exceeded
19 Execution timed out 195 ms 28004 KB Time limit exceeded
20 Execution timed out 591 ms 31224 KB Time limit exceeded