Submission #208509

# Submission time Handle Problem Language Result Execution time Memory
208509 2020-03-11T11:30:33 Z srvlt Sails (IOI07_sails) C++14
15 / 100
1000 ms 2296 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], tmp[N], f[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];
        f[h[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 = mx; i >= 1; i--) {
        f[i] += f[i + 1];
    }
    for (int i = 1; i < mx; i++) {
        int l = max(0, (cnt[i + 1] - cnt[i] + 1) / 2), r = f[i] - cnt[i];
        for (int j = l; j <= r; j++) {
            for (int k = i + 1; k <= mx; k++) {
                tmp[k] = cnt[k];
            }
            int x = j;
            for (int k = i + 1; k <= mx; k++) {
                if (x >= tmp[k]) {
                    x -= tmp[k];
                    tmp[k] = 0;
                }   else {
                    tmp[k] -= x;
                    break;
                }
            }
            ll total = 0;
            for (int k = i + 1; k <= mx; k++) {
                total += tmp[k];
            }
            if (cnt[i] + j >= tmp[i + 1] && cnt[i] + j >= (total + (mx - i - 1)) / (mx - i)) {
                cnt[i] += j;
                for (int k = i + 1; k <= mx; k++) {
                    cnt[k] = tmp[k];
                }
                break;
            }
        }
    }
    ll ans = 0;
    for (int i = 1; i <= mx; i++) {
        ans += (ll)cnt[i] * (cnt[i] - 1) / 2;
    }
    cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 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 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 888 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 1272 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 2040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1093 ms 2168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 2296 KB Time limit exceeded
2 Halted 0 ms 0 KB -