# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
513180 | 2022-01-17T03:17:29 Z | kevin | Sails (IOI07_sails) | C++17 | 36 ms | 9276 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(i <= 7){ // cout<<h[i]<<" "; // for(auto p:v) cout<<p.f<<"|"<<p.s<<" "; // nl; // } 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 + x}); } 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 | Correct | 7 ms | 8140 KB | Output is correct |
2 | Correct | 8 ms | 8024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8012 KB | Output is correct |
2 | Incorrect | 6 ms | 8140 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8092 KB | Output is correct |
2 | Correct | 7 ms | 8060 KB | Output is 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 | 8 ms | 8164 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 8232 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 18 ms | 8784 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 8516 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 32 ms | 8516 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 36 ms | 9276 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 28 ms | 8784 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |