Submission #705681

# Submission time Handle Problem Language Result Execution time Memory
705681 2023-03-05T00:24:18 Z ToroTN Gondola (IOI14_gondola) C++14
100 / 100
47 ms 3120 KB
#include<bits/stdc++.h>
using namespace std;
#include "gondola.h"
//#include "grader.cpp"
#define X first 
#define Y second
#define pb push_back
#define ll long long
int a[100005];
int valid(int n, int s[]) {
 
    for (int i=0; i<n; ++i) {
        if (s[i]<=n) {
            int val=s[i];
            for (int j=i+1; j<n; ++j) {
                ++val;
                if (val>n) val-=n;
                if (s[j]<=n && s[j]!=val) return 0;
            }
            break;
        }
    }
 
    sort(s,s+n);
    for (int i=1; i<n; ++i) if (s[i]==s[i-1]) return 0;
 
  	return 1;
}
//----------------------
 
int replacement(int n, int gondolaSeq[], int peteza[])
{
    for(int i=0;i<n;i++)
    {
        a[i+1]=gondolaSeq[i];
    }
    int mx=0,origin[100005];
    for(int i=1;i<=n;i++)mx=max(mx,a[i]),origin[i]=i;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=n)
        {
            for(int j=i;j<i+n;j++)
            {
                if(j<=n)
                {
                    if(a[i]+j-i<=n)
                    {
                        origin[j]=a[i]+j-i;
                    }else
                    {
                        origin[j]=a[i]+j-i-n;
                    }
                }else
                {
                    if(a[i]+j-i<=n)
                    {
                        origin[j-n]=a[i]+j-i;
                    }else
                    {
                        origin[j-n]=a[i]+j-i-n;
                    }
                }
            }
            break;
        }
    }
    int it=-1;
    vector<pair<int,int> > v;
    v.pb({-1e9,-1e9});
    for(int i=1;i<=n;i++)v.pb({a[i],origin[i]});
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++)
    {
        if(v[i].X>n)
        {
            ++it;
            peteza[it]=v[i].Y;
            if(v[i-1].X>n)
            {
                for(int j=v[i-1].X+1;j<v[i].X;j++)
                {
                    ++it;
                    peteza[it]=j;
                }
            }else
            {
                for(int j=n+1;j<v[i].X;j++)
                {
                    ++it;
                    peteza[it]=j;
                }
            }
        }
    }
    return mx-n;
}
 
//----------------------
ll MOD=1e9+9;
ll power(ll base,ll num)
{
    ll powerx[35];
    powerx[0]=base;
    for(int i=1;i<=30;i++)
    {
        powerx[i]=powerx[i-1]*powerx[i-1];
        powerx[i]%=MOD;
    }
    vector<ll> vec;
    while(1)
    {
        if(num<=1)
        {
            vec.pb(num);
            break;
        }
        vec.pb(num%2);
        num/=2;
    }
    ll super=1;
    for(int i=0;i<vec.size();i++)
    {
        if(vec[i]==1)
        {
            super*=powerx[i];
            super%=MOD;
        }
    }
    return super;
}
int countReplacement(int n, int inputSeq[])
{
    int num=valid(n,inputSeq);
    if(num==0)return 0;
    for(int i=0;i<n;i++)
    {
        a[i+1]=inputSeq[i];
    }
    ll ans=1,cnt=0;
    vector<ll> v;
    v.pb(-1e9);
    for(int i=1;i<=n;i++)
    {
        if(a[i]>n)
        {
            v.pb(a[i]);
            ++cnt;
        }
    }
    sort(v.begin(),v.end());
    if(v.size()>=2)
    {
        for(int i=1;i<v.size();i++)
        {
            ll kuay;
            if(i==1)
            {
                kuay=v[i]-n-1;
            }else
            {
                kuay=v[i]-v[i-1]-1;
            }
            //printf("%lld %lld\n",cnt,kuay);
            ans*=power(cnt,kuay);
            ans%=MOD;
            --cnt;
        }
        //printf("\n");
    }
    if(v.size()==n+1)
    {
        ans*=n;
        ans%=MOD;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'long long int power(long long int, long long int)':
gondola.cpp:122:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |     for(int i=0;i<vec.size();i++)
      |                 ~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:154:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |         for(int i=1;i<v.size();i++)
      |                     ~^~~~~~~~~
gondola.cpp:171:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  171 |     if(v.size()==n+1)
      |        ~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 460 KB Output is correct
7 Correct 10 ms 656 KB Output is correct
8 Correct 7 ms 468 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 11 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 8 ms 456 KB Output is correct
7 Correct 7 ms 564 KB Output is correct
8 Correct 11 ms 468 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 13 ms 612 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 7 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 10 ms 2412 KB Output is correct
12 Correct 21 ms 2508 KB Output is correct
13 Correct 17 ms 1724 KB Output is correct
14 Correct 12 ms 2452 KB Output is correct
15 Correct 19 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 35 ms 1992 KB Output is correct
10 Correct 24 ms 1736 KB Output is correct
11 Correct 11 ms 940 KB Output is correct
12 Correct 13 ms 980 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 31 ms 1936 KB Output is correct
10 Correct 24 ms 1764 KB Output is correct
11 Correct 11 ms 980 KB Output is correct
12 Correct 14 ms 1088 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 45 ms 2852 KB Output is correct
15 Correct 47 ms 3120 KB Output is correct
16 Correct 9 ms 964 KB Output is correct
17 Correct 32 ms 2000 KB Output is correct
18 Correct 20 ms 1488 KB Output is correct