Submission #446817

# Submission time Handle Problem Language Result Execution time Memory
446817 2021-07-23T11:18:05 Z Deepesson Gondola (IOI14_gondola) C++17
100 / 100
77 ms 6380 KB
#include <bits/stdc++.h>
#include <gondola.h>

int valid(int n, int inputSeq[])
{
    std::map<int,bool> existe;
    for(int i = 0;i!=n;++i){
        auto&x=inputSeq[i];
        if(existe[x]){
            return false;
        }
        existe[x]=true;
    }
    int ind = -1;
    int val=1e6;
    for(int i=0;i!=n;++i){
        if(inputSeq[i]<=n){
            if(inputSeq[i]<val){
                val=inputSeq[i];
                ind=i;
            }
        }
    }
    if(ind==-1)ind=0;
    if(val>n){return true;}
    int imaginario[n];
    int count = inputSeq[ind];
    if(ind==-1)count=0;
    for(int i=ind;i!=n;++i){
        imaginario[i]=count;
        ++count;
    }
    for(int i=0;i!=ind;++i){
        imaginario[i]=count;
        ++count;
    }
    for(int i=0;i!=n;++i) {
        if(inputSeq[i]>n)continue;
        if(inputSeq[i]!=imaginario[i]){return false;}
    }
    return true;

}

//----------------------
long long modpow(long long a,long long b){
    if(!b)return 1;
    const long long mod = 1e9+9;
    typedef std::pair<long long,long long> pll;
    std::vector<pll> vec;
    long long c = 1;
    long long val = a;
    vec.push_back({1,val});
    while(c<b){
        c*=2;
        val=(val*val)%mod;
        vec.push_back({c,val});
    }
    long long resp = 1;
    while(vec.size()){
        while(vec.back().first<=b){
            b-=vec.back().first;
            resp=(resp*vec.back().second)%mod;
        }
        vec.pop_back();
    }
    return resp;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  int array[n];
  for(int i=0;i!=n;++i)
    array[i]=gondolaSeq[i];
  std::map<int,int> vec;
  int max=0;
  for(int i=0;i!=n;++i){
    if(array[i]>n){
        vec[array[i]]=i;
        max=std::max(max,array[i]);
    }
  }
  if(!max)return 0;
  int cursor=0;
  int ind = -1;
  int val=1e6;
  for(int i=0;i!=n;++i){
    if(array[i]<=n){
        if(array[i]<val){
            val=array[i];
            ind=i;
        }
    }
  }
  int imaginario[n];
  int count = array[ind];
  if(ind==-1){count=1;ind=0;}
  for(int i=ind;i!=n;++i){
    imaginario[i]=count%(n);
    if(!imaginario[i])imaginario[i]=n;
    ++count;
  }
  for(int i=0;i!=ind;++i){
    imaginario[i]=count%(n);
    if(!imaginario[i])imaginario[i]=n;
    ++count;
  }
  for(;;){
    int proxima_gondola = cursor+n+1;
    auto it = vec.find(proxima_gondola);
    if(it==vec.end()){
        int subs = vec.begin()->second;
        replacementSeq[cursor]=imaginario[subs];
        imaginario[subs]=proxima_gondola;
    }else {
        int subs = it->second;
        replacementSeq[cursor]=imaginario[subs];
        imaginario[subs]=proxima_gondola;
        vec.erase(it);
    }
    ++cursor;
    if(!vec.size())break;
  }
  return cursor;
}

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

int countReplacement(int n, int inputSeq[])
{
  if(!valid(n,inputSeq))return 0;
  int array[n];
  for(int i=0;i!=n;++i)
    array[i]=inputSeq[i];
  std::priority_queue<int,std::vector<int>,std::greater<int>> queue;
  int count=0;
  for(int i=0;i!=n;++i){
    if(array[i]>n){
        queue.push(array[i]);
        count++;
    }
  }
  int gondola = n+1;
  long long resp = 1;
  if(count==n)resp=n;
  const long long mod = 1e9+9;
  while(count){
    int proximo = queue.top();
    int movs = proximo-gondola;
    long long x = modpow(count,movs);
    gondola=queue.top()+1;
    queue.pop();
    resp=(resp*x)%mod;
    --count;
  }
  return resp;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 16 ms 2276 KB Output is correct
7 Correct 17 ms 588 KB Output is correct
8 Correct 31 ms 4088 KB Output is correct
9 Correct 8 ms 1484 KB Output is correct
10 Correct 35 ms 4876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 10 ms 620 KB Output is correct
8 Correct 30 ms 4116 KB Output is correct
9 Correct 8 ms 1508 KB Output is correct
10 Correct 35 ms 4796 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 18 ms 2124 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 46 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 9 ms 844 KB Output is correct
12 Correct 10 ms 972 KB Output is correct
13 Correct 24 ms 2764 KB Output is correct
14 Correct 9 ms 912 KB Output is correct
15 Correct 28 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 56 ms 4224 KB Output is correct
10 Correct 40 ms 3576 KB Output is correct
11 Correct 17 ms 1516 KB Output is correct
12 Correct 19 ms 1740 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 58 ms 4548 KB Output is correct
10 Correct 42 ms 3620 KB Output is correct
11 Correct 15 ms 1456 KB Output is correct
12 Correct 19 ms 1724 KB Output is correct
13 Correct 4 ms 664 KB Output is correct
14 Correct 66 ms 4760 KB Output is correct
15 Correct 77 ms 6380 KB Output is correct
16 Correct 12 ms 1344 KB Output is correct
17 Correct 51 ms 4368 KB Output is correct
18 Correct 28 ms 2508 KB Output is correct