Submission #899712

# Submission time Handle Problem Language Result Execution time Memory
899712 2024-01-06T22:40:16 Z ivaziva A Huge Tower (CEOI10_tower) C++17
85 / 100
1000 ms 18616 KB
#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000009

long long n,d;
vector<long long> niz;
vector<long long> val;
vector<long long> levo,desno;

void mergee(long long l,long long mid,long long r)
{
    for (long long i=l;i<=mid;i++) levo.push_back(niz[i]);
    for (long long i=mid+1;i<=r;i++) desno.push_back(niz[i]);
    long long poz1=0,poz2=0;
    long long poz=l;
    while (poz1<levo.size() and poz2<desno.size())
    {
        if (levo[poz1]<desno[poz2])
        {
            niz[poz]=levo[poz1];
            poz1++;poz++;
        }
        else
        {
            niz[poz]=desno[poz2];
            poz2++;poz++;
        }
    }
    while (poz1<levo.size())
    {
        niz[poz]=levo[poz1];
        poz1++;poz++;
    }
    while (poz2<desno.size())
    {
        niz[poz]=desno[poz2];
        poz2++;poz++;
    }
    levo.clear();desno.clear();
}

void mergesort(long long l,long long r)
{
    if (l>=r) return;
    long long mid=(l+r)/2;
    mergesort(l,mid);
    mergesort(mid+1,r);
    mergee(l,mid,r);
}

int main()
{
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>d;
    niz.push_back(0); val.push_back(0);
    for (long long i=1;i<=n;i++)
    {
        long long x; cin>>x;
        niz.push_back(x);
    }
    mergesort(1,n);
    for (long long i=1;i<=n;i++)
    {
        long long br=0;
        for (long long j=i-1;j>=1;j--)
        {
            if (niz[i]-niz[j]<=d) br++;
            else break;
        }
        val.push_back(br);
    }
    long long ans=1;
    for (long long i=1;i<=n;i++)
    {
        ans*=(val[i]+1);
        if (ans>=MOD) ans%=MOD;
    }
    cout<<ans<<endl;
}

Compilation message

tower.cpp: In function 'void mergee(long long int, long long int, long long int)':
tower.cpp:18:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while (poz1<levo.size() and poz2<desno.size())
      |            ~~~~^~~~~~~~~~~~
tower.cpp:18:37: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while (poz1<levo.size() and poz2<desno.size())
      |                                 ~~~~^~~~~~~~~~~~~
tower.cpp:31:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     while (poz1<levo.size())
      |            ~~~~^~~~~~~~~~~~
tower.cpp:36:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     while (poz2<desno.size())
      |            ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2004 KB Output is correct
2 Execution timed out 1072 ms 2096 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 575 ms 8652 KB Output is correct
2 Execution timed out 1058 ms 5576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 18616 KB Time limit exceeded
2 Halted 0 ms 0 KB -