Submission #208504

# Submission time Handle Problem Language Result Execution time Memory
208504 2020-03-11T11:08:45 Z srvlt Sails (IOI07_sails) C++14
15 / 100
1000 ms 1528 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 100007;
int n, h[N], k[N], cnt[N];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        cin >> h[i] >> k[i];
        cnt[h[i] - k[i] + 1]++;
        cnt[h[i] + 1]--;
        mx = max(mx, h[i]);
    }
    for (int i = 1; i <= mx; i++) {
        cnt[i] += cnt[i - 1];
    }
    for (int i = 1; i < mx; i++) {
        ll s = 0, cur = cnt[i], nxt = cnt[i + 1];
        for (int j = i + 1; j <= mx; j++) {
            s += cnt[j];
        }
        ll l = (nxt - cur + 1) / 2 - 1, r = (ll)1e10 + 1;
        if (l < -1) {
            l = -1;
        }
        while (l < r - 1) {
            ll mid = (l + r) / 2;
            if ((s - mid + (mx - i - 1)) / (mx - i) <= cur + mid) {
                r = mid;
            }   else {
                l = mid;
            }
        }
        cnt[i] += r;
        for (int j = i + 1; j <= mx; j++) {
            if (r >= cnt[j]) {
                r -= cnt[j];
                cnt[j] = 0;
            }   else {
                cnt[j] -= r;
                r = 0;
                break;
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= mx; i++) {
        ll x = cnt[i];
        ans += x * (x - 1) / 2;
    }
    cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 374 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 306 ms 752 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 858 ms 1016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 1272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 1400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 1528 KB Time limit exceeded
2 Halted 0 ms 0 KB -