답안 #1017850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017850 2024-07-09T10:45:00 Z simona1230 곤돌라 (IOI14_gondola) C++17
100 / 100
85 ms 11448 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+9;

long long mult(long long x,long long p)
{
    if(p==0)return 1;
    if(p==1)return x;
    long long half=mult(x,p/2);
    if(p%2==0)return (half*half)%mod;
    return (((half*half)%mod)*x)%mod;
}
int n;
long long a[250001];
map<long long,long long> mp;
bool check()
{
    mp.clear();
    long long idx=-1;
    for(int i=0; i<n; i++)
    {
        if(mp[a[i]])return 0;
        mp[a[i]]++;
        if(a[i]<=n)
        {
            idx=i;
        }
    }
    if(idx==-1)return 1;

    long long curr=a[idx];
    for(int i=idx; i<n; i++)
    {
        if(a[i]<=n&&a[i]!=curr)return 0;
        curr++;
        if(curr==n+1)curr=1;
    }

    for(int i=0; i<idx; i++)
    {
        if(a[i]<=n&&a[i]!=curr)return 0;
        curr++;
        if(curr==n+1)curr=1;
    }
    return 1;
}

int valid(int N, int inputSeq[])
{
    n=N;
    for(int i=0; i<n; i++)
        a[i]=inputSeq[i];
    //cout<<check()<<endl;
    return check();
}

//----------------------


int req[250001];
void needed()
{
    int idx=-1;
    for(int i=0; i<n; i++)
    {
        if(a[i]<=n)
        {
            idx=i;
        }
    }
    if(idx==-1)
    {
        for(int i=0; i<n; i++)
            req[i]=i+1;
        return;
    }

    int curr=a[idx];
    for(int i=idx; i<n; i++)
    {
        req[i]=curr;
        curr++;
        if(curr==n+1)curr=1;
    }

    for(int i=0; i<idx; i++)
    {
        req[i]=curr;
        curr++;
        if(curr==n+1)curr=1;
    }
}

bool cmp(int i,int j)
{
    return a[i]<a[j];
}

int replacement(int N, int gondolaSeq[], int replacementSeq[])
{
    n=N;
    for(int i=0; i<n; i++)
        a[i]=gondolaSeq[i];
    needed();
    vector<int> v;
    for(int i=0; i<n; i++)
    {
        if(a[i]!=req[i])v.push_back(i);
    }
    sort(v.begin(),v.end(),cmp);

    /*for(int i=0;i<n;i++)
        cout<<req[i]<<" ";
    cout<<endl;*/
    int all=n+1;
    int cnt=0;
    for(int i=0; i<v.size(); i++)
    {
        int idx=v[i];
        //cout<<req[idx]<<endl;
        while(req[idx]!=a[idx])
        {
            replacementSeq[cnt++]=req[idx];
            req[idx]=all++;
        }
    }
    return cnt;
}

//----------------------
int countReplacement(int N, int inputSeq[])
{
    n=N;
    for(int i=0; i<n; i++)
        a[i]=inputSeq[i];
    if(check()==0)return 0;
    needed();
    vector<long long> v;
    mp.clear();
    long long maxx=n+1;
    for(int i=0; i<n; i++)
    {
        mp[a[i]]=i;
        maxx=min(maxx,a[i]);
        if(a[i]!=req[i])v.push_back(i);
        if(req[i]==n)mp[n]=i;
    }
    sort(v.begin(),v.end(),cmp);
    long long ans=1;
    long long last=n;
    for(int i=0; i<v.size(); i++)
    {
        long long pos=v.size()-i;
        long long cnt=a[v[i]]-last-1;
        //cout<<last<<" "<<a[v[i]]<<" "<<pos<<" "<<cnt<<endl;
        ans=(ans*mult(pos,cnt))%mod;
        last=a[v[i]];
    }

    if(v.size()==n)
    {
        ans=(ans*n)%mod;
    }

    return (int)ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:118:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for(int i=0; i<v.size(); i++)
      |                  ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:152:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  152 |     for(int i=0; i<v.size(); i++)
      |                  ~^~~~~~~~~
gondola.cpp:161:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  161 |     if(v.size()==n)
      |        ~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 10 ms 6748 KB Output is correct
7 Correct 6 ms 4696 KB Output is correct
8 Correct 23 ms 8876 KB Output is correct
9 Correct 7 ms 5724 KB Output is correct
10 Correct 25 ms 9632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 10 ms 4956 KB Output is correct
7 Correct 5 ms 2652 KB Output is correct
8 Correct 21 ms 8796 KB Output is correct
9 Correct 6 ms 5788 KB Output is correct
10 Correct 24 ms 9564 KB Output is correct
11 Correct 0 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 16 ms 6524 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 32 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 0 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 11 ms 1628 KB Output is correct
12 Correct 6 ms 1628 KB Output is correct
13 Correct 11 ms 1760 KB Output is correct
14 Correct 11 ms 1624 KB Output is correct
15 Correct 15 ms 2584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 57 ms 9804 KB Output is correct
10 Correct 39 ms 8788 KB Output is correct
11 Correct 17 ms 4324 KB Output is correct
12 Correct 18 ms 4684 KB Output is correct
13 Correct 4 ms 2972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 62 ms 7964 KB Output is correct
10 Correct 39 ms 8776 KB Output is correct
11 Correct 15 ms 6236 KB Output is correct
12 Correct 19 ms 6516 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 78 ms 10960 KB Output is correct
15 Correct 85 ms 11448 KB Output is correct
16 Correct 11 ms 5976 KB Output is correct
17 Correct 47 ms 7252 KB Output is correct
18 Correct 25 ms 7256 KB Output is correct