# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
513174 | 2022-01-17T03:03:41 Z | kevin | Sails (IOI07_sails) | C++17 | 25 ms | 10288 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define nl cout<<"\n" #define f first #define s second #define ca(v) for(auto i:v) cout<<i<<" "; const int MAXN = 1000000; ll h[MAXN + 5]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("input.in", "r")) freopen("input.in", "r", stdin); int n; cin>>n; for(int i=0; i<n; i++){ ll H, K; cin>>H>>K; h[H-K+1]++; h[H+1]--; } for(int i=1; i<=MAXN; i++){ h[i] += h[i-1]; } vector<pair<ll, ll>> v; for(int i=1; i<=MAXN; i++){ if(!h[i]) continue; if(v.size() == 0){ if(i == 1) { v.push_back({1, h[i]}); continue; } v.push_back({i-1, 0}); } if(h[i] < v.back().s) v.push_back({1, h[i]}); else{ h[i] -= v.back().s; v[v.size()-1].f++; while(h[i]){ if(v.size() == 1 || abs(v.back().s - v[v.size()-2].s) * v.back().f >= h[i]){ pair<ll, ll> tmp = v.back(); v.pop_back(); ll x = h[i] / tmp.f; ll r = h[i] % tmp.f; if(!r) v.push_back({tmp.f, tmp.s + x}); else{ v.push_back({tmp.f - r, tmp.s + x + 1}); v.push_back({r, tmp.s}); } h[i] = 0; } else{ h[i] -= abs(v.back().s - v[v.size()-2].s) * v.back().f; v[v.size()-2].f += v.back().f; v.pop_back(); } } } } ll ans = 0; for(auto p:v){ // cout<<p.f<<" "<<p.s<<"\n"; ans += (ll)p.f * (p.s * (p.s - 1) / 2); } cout<<ans<<"\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 8132 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8128 KB | Output is correct |
2 | Incorrect | 7 ms | 8128 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 8140 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 8140 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 8140 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 8396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 9092 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 9048 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 20 ms | 9272 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 25 ms | 10288 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 9908 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |