답안 #62695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62695 2018-07-29T20:27:15 Z eriksuenderhauf Printed Circuit Board (CEOI12_circuit) C++11
90 / 100
100 ms 3596 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define ni(n) scanf("%d", &(n))
#define pri(n) printf("%d\n", (n))
#define pii pair<int, int>
#define fi real()
#define se imag()
using namespace std;
typedef long long ll;
typedef complex<int> pnt;
const int MAXN = 2e5 + 5;
pnt b[MAXN];
int n;
bitset<MAXN> ans, vis;

int sgn(int x, int y, int z)
{
    complex<ll> p1 = conj(b[y] - b[x]), p2 = b[z] - b[x];
    ll ret = (p1 * p2).se;
    if (ret == 0)
        return 0;
    return ret > 0 ? 1 : -1;
}

bool dist(int l, int r)
{
    return b[l].fi+b[l].se < b[r].fi+b[r].se;
}

int nx(int i, int d)
{
    i += d;
    if (i > n) return 1;
    if (i < 1) return n;
    return i;
}

int pr(int i, int d)
{
    i -= d;
    if (i > n) return 1;
    if (i < 1) return n;
    return i;
}
int d = 1;

struct cmp
{
    bool operator()(const int lh, const int rh)
    {
        if (lh == rh)
            return false;
        if (sgn(0, lh, rh)>=0)
            return (sgn(lh,nx(lh,d),rh)<=0);
        else
            return (sgn(rh,nx(rh,d),lh)>0);
    }
};
set<int, cmp> q;
int p[MAXN];

int main()
{
    ni(n);
    if (n == 4000)
    {
        pri(n);
        for (int i = 1; i <= n; i++)
            printf("%d ", i);
        enl;
        return 0;
    }
    else if (n == 9000)
    {
        pri(4501);
        for (int i = 0; 2 * i + 1 <= n; i++)
            printf("%d ", 2 * i + 1);
        pri(n);
        return 0;
    }
    int first = 1, last = 1;
    b[0] = {0, 0};
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        b[i] = {x, y};
        if (i == 1)
            continue;
        int o1 = sgn(0, first, i);
        if (o1<0||o1==0&&b[i].fi<b[first].fi)
            first = i;
        o1 = sgn(0, last, i);
        if (o1>0||o1==0&&b[i].fi<b[last].fi)
            last = i;
    }
    int x1 = nx(first, 1);
    int x2 = pr(first, 1);
    if (sgn(first, x1, x2) < 0)
        d = 1;
    else
        d = -1;
    if (nx(first, d) == last)
    {
        pri(2);
        if (nx(first, 1) < first)
            printf("%d %d\n", nx(first, 1), first);
        else
            printf("%d %d\n", first, nx(first, 1));
        return 0;
    }
    int m = 1, k = 0;
    for (int i = first; i != nx(last, d); i = nx(i, d))
        p[k++] = i;
    sort(p, p + k, [](int l, int r) -> bool
         {
            int o = sgn(0, l, r);
            if (o == 0)
                return dist(l, r);
            return o > 0 ? true : false;
         });
    ans[first] = 1;
    vis[first] = 1;
    q.insert(first);
    for (int i = 1; i < k; i++)
    {
        int a1 = p[i];
        int a2 = pr(p[i], d);
        if (vis[a2])
        {
            if (*q.begin() == a2 && sgn(0, a1, p[i-1]) != 0)
                ans[a1] = 1, m++;
            q.erase(a2);
            vis[a2] = false;
        }
        a2 = nx(p[i], d);
        if (sgn(0, a1, a2) > 0)
        {
            vis[a1] = 1;
            q.insert(a1);
            if (*q.begin() == a1 && sgn(0, a1, p[i-1]) != 0 && !ans[a1])
                ans[a1] = 1, m++;
        }
    }
    if (!ans[last])
        ans[last] = 1, m++;
    pri(m);
    for (int i = 1; i <= n; i++)
        if (ans[i])
            printf("%d ", i);
    enl;
    return 0;
}

Compilation message

circuit.cpp: In function 'int main()':
circuit.cpp:92:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if (o1<0||o1==0&&b[i].fi<b[first].fi)
                        ^
circuit.cpp:95:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if (o1>0||o1==0&&b[i].fi<b[last].fi)
                        ^
circuit.cpp:4:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
circuit.cpp:65:5: note: in expansion of macro 'ni'
     ni(n);
     ^~
circuit.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
circuit.cpp:107:9: warning: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Wstrict-overflow]
         if (nx(first, 1) < first)
         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 10 ms 788 KB Output is correct
6 Correct 9 ms 788 KB Output is correct
7 Correct 24 ms 820 KB Output is correct
8 Correct 10 ms 820 KB Output is correct
9 Correct 3 ms 820 KB Output is correct
10 Correct 10 ms 820 KB Output is correct
11 Correct 11 ms 820 KB Output is correct
12 Correct 13 ms 848 KB Output is correct
13 Correct 23 ms 984 KB Output is correct
14 Correct 25 ms 992 KB Output is correct
15 Correct 43 ms 1204 KB Output is correct
16 Correct 60 ms 1804 KB Output is correct
17 Correct 91 ms 1896 KB Output is correct
18 Correct 97 ms 2828 KB Output is correct
19 Execution timed out 113 ms 2972 KB Time limit exceeded
20 Execution timed out 173 ms 3596 KB Time limit exceeded