답안 #852312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852312 2023-09-21T15:01:05 Z DobromirAngelov 곤돌라 (IOI14_gondola) C++14
55 / 100
31 ms 4616 KB
#include "gondola.h"
#include<bits/stdc++.h>

using namespace std;

const int MAXN=1e5+5;
const int MOD=1e9+9;

map<int,int> m;

int valid(int n, int a[])
{
    for(int i=0;i<n;i++)
    {
        if(m[a[i]]!=0) return 0;
        m[a[i]]=1;
    }

    int mn=1e9, idx=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<mn)
        {
            mn=a[i];
            idx=i;
        }
    }
    if(mn<=n)
    {
        int cur=mn+1;
        for(int i=idx+1;i!=idx;i++)
        {
            if(i>=n) i-=n;
            if(a[i]<=n && a[i]!=cur) return 0;
            cur++;
            if(i==n-1) i=-1;
        }
    }

    return 1;
}

int b[MAXN];
vector<pair<int,int> > v;

int replacement(int n, int a[], int replacementSeq[])
{
    int mn=1e9,idx=-1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<mn)
        {
            mn=a[i];
            idx=i;
        }
    }

    if(mn>n)
    {
        for(int i=0;i<n;i++) b[i]=i+1;
    }
    else
    {
        int cur=mn;
        b[idx]=cur++;
        for(int i=idx+1;i!=idx;i++)
        {
            if(i>=n) i-=n;
            if(cur>n) cur-=n;
            b[i]=cur++;
            if(i==n-1) i=-1;
        }
    }

    for(int i=0;i<n;i++)
    {
        if(a[i]>n) v.push_back({a[i],b[i]});
    }

    sort(v.begin(), v.end());
    int ptr=0;
    int cur=n;
    for(int i=0;i<v.size();i++)
    {
        replacementSeq[ptr++]=v[i].second;
        cur++;
        while(cur<v[i].first)
        {
            replacementSeq[ptr++]=cur++;
        }
    }

    return ptr;
}

int fastPow(int a,int pw)
{
    long long ret=1;
    while(pw>0)
    {
        if(pw&1) ret=ret*a%MOD;
        a=(long long) a*a%MOD;
        pw/=2;
    }
    return ret;
}

vector<int> v2;

int countReplacement(int n, int a[])
{
    if(!valid(n,a)) return 0;

    for(int i=0;i<n;i++)
    {
        if(a[i]>n) v2.push_back(a[i]);
    }
    v2.push_back(n);

    sort(v2.begin(), v2.end());
    long long ans=1;
    for(int i=1;i<v2.size();i++)
    {
        ans=ans*fastPow(v2.size()-i, v2[i]-v2[i-1])%MOD;
    }

    if(v2.size()==n+1) ans=ans*n%MOD;

    return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:122:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |     for(int i=1;i<v2.size();i++)
      |                 ~^~~~~~~~~~
gondola.cpp:127:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  127 |     if(v2.size()==n+1) ans=ans*n%MOD;
      |        ~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 2336 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 24 ms 3924 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 22 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 7 ms 760 KB Output is correct
8 Correct 19 ms 3920 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 22 ms 4580 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 14 ms 2140 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 31 ms 4616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 552 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 344 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 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 6 ms 1020 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 11 ms 1752 KB Output is correct
14 Correct 6 ms 860 KB Output is correct
15 Correct 16 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -