Submission #1064643

# Submission time Handle Problem Language Result Execution time Memory
1064643 2024-08-18T16:15:27 Z NemanjaSo2005 Gondola (IOI14_gondola) C++17
100 / 100
52 ms 6792 KB
#include "gondola.h"
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
const int maxn=1e5+5;
int N,niz[maxn],niz2[maxn];
ll res=0;
const ll MOD=1e9+9;
set<int> S;
void adjust(){
   int najm=1;
   for(int i=1;i<=N;i++)
      if(niz[i]<niz[najm])
         najm=i;
   for(int i=1;i<=N;i++){
      if(i+najm-1<=N)
         niz2[i]=niz[i+najm-1];
      else
         niz2[i]=niz[i+najm-N-1];
   }
   for(int i=1;i<=N;i++)
      niz[i]=niz2[i];
}
int valid(int n, int inputSeq[]){
   N=n;
   for(int i=1;i<=N;i++){
      niz[i]=inputSeq[i-1];
   }
   for(int i=1;i<=N;i++){
      if(S.find(niz[i])!=S.end())
         return 0;
      S.insert(niz[i]);
   }
   S.clear();
   adjust();/*
   for(int i=1;i<=N;i++)
      cout<<niz[i]<<" ";
   cout<<endl;*/
   if(niz[1]>=N)
      return 1;
   int treba=niz[1];
   for(int i=2;i<=N;i++){
      treba++;
      if(niz[i]>N)
         continue;
      if(niz[i]!=treba)
         return 0;
   }
   return 1;
}
vector<pair<int,int>> V;
void makepairs(){
   int treba=niz[1];
   if(treba>N)
      treba=1;
   for(int i=1;i<=N;i++){
      V.push_back({niz[i],treba});
      treba++;
      if(treba>N)
         treba=1;
   }
   sort(V.begin(),V.end());
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
   N=n;
   for(int i=1;i<=N;i++)
      niz[i]=gondolaSeq[i-1];
   adjust();
   makepairs();
   int sled=N+1;
   vector<int> R;
   for(auto x:V){
      while(sled<=x.first){
         R.push_back(x.second);
         x.second=sled;
         sled++;
      }
   }
   for(int i=0;i<R.size();i++)
      replacementSeq[i]=R[i];
   return R.size();
}
ll stepen(ll a,ll koji){
   ll ret=1;
   for(int i=1;i<=koji;i<<=1){
      if(koji&i)
         ret=ret*a%MOD;
      a=a*a%MOD;
   }
   return ret;
}
int countReplacement(int n, int inputSeq[]){
   if(valid(n,inputSeq)==0)
      return 0;
/*   for(int i=0;i<=100;i++)
      cout<<i<<": "<<stepen(3,i)<<endl;*/
   makepairs();
   int losih=0;
   for(int i=1;i<=N;i++)
      if(niz[i]>N)
         losih++;
   V.push_back({N,N});
   sort(V.begin(),V.end());
   res=1;
   for(int i=1;i<V.size();i++){
      if(V[i].f<=N)
         continue;
      res=res*stepen(losih,V[i].f-V[i-1].f-1)%MOD;
     // cout<<"MNOZI "<<losih<<" "<<V[i].f-V[i-1].f-1<<"\n";
      losih--;
   }
   if(niz[1]>N)
      res=res*N%MOD;
   return res;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:81:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |    for(int i=0;i<R.size();i++)
      |                ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:107:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |    for(int i=1;i<V.size();i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 2652 KB Output is correct
7 Correct 7 ms 1460 KB Output is correct
8 Correct 18 ms 4956 KB Output is correct
9 Correct 6 ms 1884 KB Output is correct
10 Correct 30 ms 5704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 9 ms 2652 KB Output is correct
7 Correct 6 ms 1436 KB Output is correct
8 Correct 18 ms 5028 KB Output is correct
9 Correct 6 ms 1880 KB Output is correct
10 Correct 31 ms 5724 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 352 KB Output is correct
13 Correct 14 ms 2652 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 32 ms 5968 KB Output is correct
# Verdict Execution time Memory 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 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 444 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 440 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 8 ms 2772 KB Output is correct
12 Correct 10 ms 3028 KB Output is correct
13 Correct 11 ms 2112 KB Output is correct
14 Correct 9 ms 2768 KB Output is correct
15 Correct 14 ms 2712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 36 ms 5052 KB Output is correct
10 Correct 30 ms 4168 KB Output is correct
11 Correct 10 ms 1880 KB Output is correct
12 Correct 14 ms 2112 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 35 ms 5208 KB Output is correct
10 Correct 28 ms 4180 KB Output is correct
11 Correct 10 ms 1884 KB Output is correct
12 Correct 13 ms 2140 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 45 ms 5980 KB Output is correct
15 Correct 52 ms 6792 KB Output is correct
16 Correct 8 ms 1624 KB Output is correct
17 Correct 35 ms 4560 KB Output is correct
18 Correct 18 ms 3164 KB Output is correct