Submission #29091

#TimeUsernameProblemLanguageResultExecution timeMemory
29091chpipisPrinted Circuit Board (CEOI12_circuit)C++11
65 / 100
1060 ms6056 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 1e5 + 5;

inline ll ccw(ii a, ii b, ii c) {
    return (b.fi - a.fi) * 1LL * (c.se - a.se) - (b.se - a.se) * 1LL * (c.fi - a.fi);
}

struct comp {
    inline bool operator() (ii lhs, ii rhs) {
        return ccw(ii(0, 0), lhs, rhs) > 0;
    }
};

ii pts[MAXN];
multiset<ii, comp> active;

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &pts[i].fi, &pts[i].se);
        active.insert(pts[i]);
    }
    for (int i = 0; i < n; i++) {
        ii a = pts[i], b = pts[(i + 1) % n];
        if (ccw(ii(0, 0), a, b) < 0) swap(a, b);
        auto st = active.lower_bound(a);
        auto en = active.upper_bound(b);
        while (st != en) {
            if (*st != a && *st != b && ccw(a, *st, b) > 0)
                st = active.erase(st);
            else
                st++;
        }
    }
    printf("%d\n", (int)active.size());
    vii vec(all(active));
    sort(all(vec));
    for (int i = 0; i < n; i++) {
        auto it = lower_bound(all(vec), pts[i]);
        if (it != vec.end() && *it == pts[i])
            printf("%d ", i + 1);
    }
    puts("");
    return 0;
}

Compilation message (stderr)

circuit.cpp: In function 'int main()':
circuit.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
circuit.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &pts[i].fi, &pts[i].se);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...