Submission #95460

# Submission time Handle Problem Language Result Execution time Memory
95460 2019-02-01T11:26:37 Z forestryks Printed Circuit Board (CEOI12_circuit) C++14
40 / 100
36 ms 4700 KB
///////////////////////////////////////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define f first
#define s second
#define x1 x1qwer
#define y1 y1qwer
#define right right123
#define left left123
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double DINF = numeric_limits<double>::infinity();
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw_(MOD);
uniform_int_distribution<ll> rd_;
ll randomll() { return rd_(mmtw_);}
ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
////////////////////////////////////////////////////////////////////////////////////////////////

struct pt {
    int x, y;
    int id, sid;
};

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

inline pt operator-(const pt &a) {
    return {-a.x, -a.y};
}

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

inline ll dot(const pt &a, const pt &b) {
    return 1LL * a.x * b.x + 1LL * a.y * b.y;
}

inline ll cross(const pt &a, const pt &b) {
    return 1LL * a.x * b.y - 1LL * a.y * b.x;
}

inline ll dd0(const pt &a) {
    return dot(a, a);
}

const int MAXN = 1e5 + 5;
int n;
pt a[MAXN];
bool used[MAXN];
int ord[MAXN];

inline int md(int x) {
    if (x >= n) return x - n;
    if (x < 0) return x + n;
    return x;
}

int findLowest() {
    int s = 0;
    for (int i = 0; i < n; ++i) {
        ll cr = cross(a[i], a[s] - a[i]);
        if (cr > 0 || (cr == 0 && dd0(a[i]) < dd0(a[s]))) {
            s = i;
        }
    }
    return s;
}

int findHighest() {
    int t = 0;
    for (int i = 0; i < n; ++i) {
        ll cr = cross(a[i], a[t] - a[i]);
        if (cr < 0 || (cr == 0 && dd0(a[i]) < dd0(a[t]))) {
            t = i;
        }
    }
    return t;
}

struct cmp {
    bool operator()(int i, int j) {
        if (cross(a[i], a[j]) <= 0) {
            return cross(a[j + 1] - a[j], a[i] - a[j]) > 0;
        } else {
            return cross(a[i + 1] - a[i], a[j] - a[i]) < 0;
        }
    }
};

int main() {
    FAST_IO;
    cin >> n;
    rep(i, n) {
        cin >> a[i].x >> a[i].y;
        a[i].id = i + 1;
    }

    assert(n > 2);

    int lowest = findLowest();
    if (cross(a[md(lowest - 1)] - a[lowest], a[md(lowest + 1)] - a[lowest]) < 0) {
        reverse(a, a + n);
    }

    rotate(a, a + findLowest(), a + n);
    n = findHighest() + 1;

    for (int i = 0; i < n; ++i) {
        ord[i] = i;
    }

    sort(ord, ord + n, [](int i, int j){
        int cr = cross(a[i], a[j]);
        if (cr != 0) return cr > 0;
        return dd0(a[i]) < dd0(a[j]);
    });

    vector<int> res;
    set<int, cmp> s;
    for (int ii = 0; ii < n; ++ii) {
        int i = ord[ii];

        bool add = (i + 1 < n && cross(a[i], a[i + 1] - a[i]) > 0);

        if (used[i]) {
            s.erase(s.find(i - 1));
        }

        if (!s.empty()) {
            int f = *s.begin();
            if (cross(a[f + 1] - a[f], a[i] - a[f]) > 0) res.push_back(a[i].id);
        } else {
            res.push_back(a[i].id);
        }

        if (add) {
            s.insert(i);
            used[i + 1] = true;
        }
    }

    sort(all(res));

    cout << res.size() << '\n';
    for (auto it : res) {
        cout << it << ' ';
    }
    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Runtime error 8 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 7 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 12 ms 1784 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 7 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Correct 5 ms 760 KB Output is correct
10 Runtime error 9 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 8 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Correct 8 ms 760 KB Output is correct
13 Runtime error 15 ms 2296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Correct 14 ms 1144 KB Output is correct
15 Correct 18 ms 1332 KB Output is correct
16 Incorrect 34 ms 2296 KB Output isn't correct
17 Runtime error 36 ms 4700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 21 ms 3576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 22 ms 3648 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 23 ms 3556 KB Execution killed with signal 11 (could be triggered by violating memory limits)