Submission #537613

# Submission time Handle Problem Language Result Execution time Memory
537613 2022-03-15T09:44:19 Z maomao90 Planine (COCI21_planine) C++17
50 / 110
407 ms 24784 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 1000005

int n, h;
int x[MAXN], y[MAXN];
bool used[MAXN];
int ans;

struct frac {
    ll a, b;
    frac(): a(0), b(1) {}
    frac(ll _a): a(_a), b(1) {}
    frac(ll _a, ll _b): a(_a), b(_b) {
        if (b == 0) {
            a = LINF;
            b = 1;
            return;
        }
        ll g = __gcd(abs(a), abs(b));
        a /= g;
        b /= g;
        if (b < 0) {
            a *= -1;
            b *= -1;
        }
    }
    frac operator+(const frac &o) const {
        return frac(a * o.b + b * o.a, b * o.b);
    }
    frac operator-(const frac &o) const {
        return *this + (-o);
    }
    frac operator-() const {
        return frac(-a, b);
    }
    bool operator<(const frac &o) const {
        assert(b > 0 && o.b > 0);
        return a * o.b < b * o.a;
    }
    bool operator>(const frac &o) const {
        assert(b > 0 && o.b > 0);
        return a * o.b > b * o.a;
    }
    bool operator==(const frac &o) const {
        return a == o.a && b == o.b;
    }
    bool operator<=(const frac &o) const {
        return *this == o || *this < o;
    }
    friend ostream& operator<<(ostream &os, const frac &o) {
        return os << o.a << '/' << o.b;
    }
};

struct Range {
    frac l, r;
    bool operator<(const Range &o) const {
        return r < o.r;
    }
};

vector<Range> ranges;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> n >> h;
    REP (i, 0, n) {
        cin >> x[i] >> y[i];
    }
    for (int i = 2; i < n - 1; i += 2) {
        frac l = frac(x[i]) - frac((ll) (x[i] - x[i - 1]) * (h - y[i]), y[i - 1] - y[i]);
        frac r = frac(x[i]) + frac((ll) (x[i + 1] - x[i]) * (h - y[i]), y[i + 1] - y[i]);
        if (n < 2000) {
            for (int j = i - 3; j >= 1; j -= 2) {
                if (y[j] - y[i] <= 0) continue;
                mxto(l, frac(x[i]) - frac((ll) (x[i] - x[j]) * (h - y[i]), y[j] - y[i]));
            }
            for (int j = i + 3; j < n - 1; j += 2) {
                if (y[j] - y[i] <= 0) continue;
                mnto(r, frac(x[i]) + frac((ll) (x[j] - x[i]) * (h - y[i]), y[j] - y[i]));
            }
        }
        cerr << i << ": " << l << ' ' << r << '\n';
        ranges.pb((Range) {l, r});
    }
    sort(ALL(ranges));
    REP (i, 0, ranges.size()) {
        if (used[i]) continue;
        frac x = ranges[i].r;
        ans++;
        REP (j, i, ranges.size()) {
            if (ranges[j].l <= x && x <= ranges[j].r) {
                used[j] = 1;
            } else {
                break;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
  123 |     REP (i, 0, ranges.size()) {
      |          ~~~~~~~~~~~~~~~~~~~            
Main.cpp:123:5: note: in expansion of macro 'REP'
  123 |     REP (i, 0, ranges.size()) {
      |     ^~~
Main.cpp:13:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
  127 |         REP (j, i, ranges.size()) {
      |              ~~~~~~~~~~~~~~~~~~~        
Main.cpp:127:9: note: in expansion of macro 'REP'
  127 |         REP (j, i, ranges.size()) {
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 24 ms 3272 KB Output is correct
5 Correct 32 ms 3292 KB Output is correct
6 Correct 39 ms 3288 KB Output is correct
7 Correct 253 ms 24784 KB Output is correct
8 Correct 314 ms 24784 KB Output is correct
9 Correct 407 ms 24764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 368 KB Output is correct
2 Correct 97 ms 404 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 81 ms 384 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 214 ms 484 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 24 ms 3272 KB Output is correct
5 Correct 32 ms 3292 KB Output is correct
6 Correct 39 ms 3288 KB Output is correct
7 Correct 253 ms 24784 KB Output is correct
8 Correct 314 ms 24784 KB Output is correct
9 Correct 407 ms 24764 KB Output is correct
10 Correct 98 ms 368 KB Output is correct
11 Correct 97 ms 404 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 81 ms 384 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 214 ms 484 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 299 ms 24600 KB Output is correct
18 Incorrect 270 ms 24696 KB Output isn't correct
19 Halted 0 ms 0 KB -