# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291836 | 2020-09-05T20:45:03 Z | Kastanda | Sails (IOI07_sails) | C++11 | 1000 ms | 2552 KB |
// M #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100005; int n, H[N], K[N], C[N]; inline bool Solve(int md) { memset(C, 0, sizeof(C)); for (int i = 1; i <= n; i ++) C[H[i] - K[i] + 1] ++, C[H[i] + 1] --; for (int i = 1; i < N; i ++) C[i] += C[i - 1]; ll LeftOver = 0; for (int i = N - 1; i; i --) { int tmp = min(LeftOver, (ll)md - C[i]); LeftOver -= tmp; C[i] += tmp; assert(C[i] <= md); } return !LeftOver; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i ++) scanf("%d%d", &H[i], &K[i]); int le = 0, ri = N, md; while (ri - le > 1) { md = (le + ri) >> 1; if (Solve(md)) ri = md; else le = md; } // How to do it with ri you ask? I don't know either ... Solve(ri); int ptr = 1; for (int i = N - 1; i; i --) if (C[i] == ri) { while (ptr < i && C[ptr] == ri) ptr ++; if (ptr >= i) break; C[i] --; C[ptr] ++; } vector < int > A; for (int i = 1; i < N; i ++) { vector < int > Tbo = {C[i]}; while (Tbo.size()) { if (!A.size() || A.back() >= Tbo.back()) { A.push_back(Tbo.back()); Tbo.pop_back(); continue; } int nd = (Tbo.back() - A.back() + 1) / 2; Tbo.back() -= nd; Tbo.push_back(A.back() + nd); A.pop_back(); } } assert((int)A.size() == N - 1); for (int i = 1; i < N; i ++) C[i] = A[i - 1]; for (int i = 1; i < N; i ++) assert(C[i] <= ri); bool Fail = 1; for (int i = 1; i < N; i ++) if (C[i] == ri) Fail = 0; for (int i = 2; i < N; i ++) assert(C[i - 1] >= C[i]); assert(!Fail); ll tot = 0; for (int i = 1; i < N; i ++) tot += (ll)C[i] * (C[i] - 1) / 2; printf("%lld\n", tot); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1404 KB | Output is correct |
2 | Correct | 14 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1404 KB | Output is correct |
2 | Correct | 14 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1532 KB | Output is correct |
2 | Correct | 14 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1404 KB | Output is correct |
2 | Correct | 14 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 1404 KB | Output is correct |
2 | Correct | 15 ms | 1436 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 1404 KB | Output is correct |
2 | Correct | 23 ms | 1660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 1660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 1780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 1908 KB | Output is correct |
2 | Correct | 41 ms | 1908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 2036 KB | Output is correct |
2 | Correct | 43 ms | 2036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 2292 KB | Output is correct |
2 | Execution timed out | 1092 ms | 2552 KB | Time limit exceeded |