Submission #370660

# Submission time Handle Problem Language Result Execution time Memory
370660 2021-02-24T12:18:59 Z TLP39 Sails (IOI07_sails) C++14
100 / 100
86 ms 8684 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long int n;
    scanf("%lld",&n);
    pair<long long int,long long int> kh[n];
    long long int k,h;
    for(long long int i=0;i<n;i++)
    {
        scanf("%lld %lld",&k,&h);
        kh[i]={k,h};
    }
    sort(kh,kh+n);
    map<long long int,long long int> change;
    long long int ma=0,mi=100001;
    auto it=change.begin();
    long long int ch,hol1;
    for(long long int i=0;i<n;i++)
    {
        k=kh[i].first;
        h=kh[i].second;
        if(k>ma && mi)
        {
            change[ma]=mi;
            mi=0;
        }
        ma=k;
        it=change.upper_bound(k-h);
        it--;
        if((*it).first==k-h)
        {
            (*it).second--;
            if((*it).second==0) change.erase(it);
            mi++;
        }
        else
        {
            ch=0;
            hol1=(*it).first;
            it++;
            if(it==change.end()) ch=1;
            if(ch)
            {
                change[h+hol1]=1;
                change[hol1]--;
                if(!change[hol1]) change.erase(hol1);
            }
            else
            {
                mi++;
                change[hol1+((*it).first)-k+h]=1;
                change[hol1]--;
                if(!change[hol1]) change.erase(hol1);
                change[(*it).first]--;
                if(!change[(*it).first]) change.erase(it);
            }
        }
    }
    long long int val=100001;
    long long int ans=0;
    for(long long int i=0;i<ma;i++)
    {
        val-=change[i];
        ans+=val*(val-1)/2;
    }
    printf("%lld",ans);
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
sails.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |         scanf("%lld %lld",&k,&h);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 25 ms 6636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2284 KB Output is correct
2 Correct 15 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 4348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7788 KB Output is correct
2 Correct 63 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 7916 KB Output is correct
2 Correct 52 ms 8044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 8172 KB Output is correct
2 Correct 42 ms 4844 KB Output is correct