Submission #890420

# Submission time Handle Problem Language Result Execution time Memory
890420 2023-12-21T07:00:38 Z Sir_Ahmed_Imran Sails (IOI07_sails) C++17
10 / 100
618 ms 2696 KB
                              ///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long 
#define append push_back
#define all(x) (x).begin(),(x).end()
void solve(){
    ll o,p,q;
    int n,m,r;
    cin>>n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++){
        cin>>p>>q;
        v.append({p,q});
    }
    sort(all(v));
    vector<pair<int,int>> Q{{0,v[0].ff}};
    o=0;
    p=v[0].ff;
    vector<pair<int,int>> u;
    for(auto& i:v){
        if(i.ff>p){
            if(Q.back().ff==0)
                Q.back().ss+=i.ff-p;
            else Q.append({0,i.ff-p});
        }
        while(i.ss>=Q.back().ss){
            u.append(Q.back());
            i.ss-=u.back().ss;
            u.back().ff++;
            Q.pop_back();
        }
        if(i.ss){
            u.append({Q.back().ff,Q.back().ss-i.ss});
            u.append({Q.back().ff+1,i.ss});
            Q.pop_back();
        }
        while(!u.empty()){
            if(Q.empty()) Q.append(u.back());
            else if(Q.back().ff==u.back().ff)
                Q.back().ss+=u.back().ss;
            else Q.append(u.back());
            u.pop_back();
        }
        p=i.ff;
    }
    for(auto& i:Q){
        p=i.ff;
        q=i.ss;
        o+=(q*p*(p-1))/2;
    }
    cout<<o<<nl;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    solve();
    return 0;
}

Compilation message

sails.cpp: In function 'void solve()':
sails.cpp:12:11: warning: unused variable 'm' [-Wunused-variable]
   12 |     int n,m,r;
      |           ^
sails.cpp:12:13: warning: unused variable 'r' [-Wunused-variable]
   12 |     int n,m,r;
      |             ^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 600 KB Output is correct
2 Runtime error 7 ms 1244 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 322 ms 1492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 1512 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 2004 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 618 ms 2696 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 2260 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -