Submission #991837

# Submission time Handle Problem Language Result Execution time Memory
991837 2024-06-03T08:34:38 Z huutuan Gondola (IOI14_gondola) C++14
75 / 100
41 ms 4636 KB
#include "gondola.h"

#include <bits/stdc++.h>

using namespace std;

int valid(int n, int inputSeq[])
{
   set<int> st;
   for (int i=0; i<n; ++i) if (inputSeq[i]<=n && inputSeq[(i+1)%n]<=n){
      if (inputSeq[i]%n+1!=inputSeq[(i+1)%n]){
         return 0;
      }
   }
   for (int i=0; i<n; ++i) if (!st.insert(inputSeq[i]).second) return 0; 
   return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
   int max_id=max_element(gondolaSeq, gondolaSeq+n)-gondolaSeq;
   int max_val=gondolaSeq[max_id];
   vector<int> pos(3e5, -1);
   vector<int> perm(n);
   iota(perm.begin(), perm.end(), 1);
   for (int i=0; i<n; ++i) pos[gondolaSeq[i]]=i;
   for (int i=0; i<n; ++i) if (gondolaSeq[i]<=n){
      perm[i]=gondolaSeq[i];
      for (int j=(i+1)%n, k=perm[i]%n+1; j!=i; j=(j+1)%n, k=k%n+1) perm[j]=k;
      break; 
   }
   int cnt=0;
   for (int i=n+1; i<=max_val; ++i){
      if (pos[i]!=-1){
         replacementSeq[cnt++]=perm[pos[i]];
         perm[pos[i]]=i;
      }else{
         replacementSeq[cnt++]=perm[max_id];
         perm[max_id]=i;
      }
   }
   return cnt;
}

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

const int mod=1e9+9;

int binpow(int x, int y){
   int t=1;
   while (y){
      if (y&1) t=1ll*t*x%mod;
      x=1ll*x*x%mod;
      y>>=1;
   }
   return t;
}

int countReplacement(int n, int inputSeq[])
{
   if (!valid(n, inputSeq)) return 0;
   int max_id=max_element(inputSeq, inputSeq+n)-inputSeq;
   int max_val=inputSeq[max_id];
   int ans=1;
   // for (int i=1; i<=n; ++i) ans=1ll*ans*i%mod;
   set<int> st(inputSeq, inputSeq+n);
   int cnt=n;
   for (int i=0; i<n; ++i) if (inputSeq[i]<=n){
      ans=1;
      --cnt;
   }
   int cur=n+1;
   for (int i:st){
      if (i<=n) continue;
      ans=1ll*ans*binpow(cnt, i-cur)%mod;
      --cnt;
      cur=i+1;
   }
   return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:65:8: warning: unused variable 'max_val' [-Wunused-variable]
   65 |    int max_val=inputSeq[max_id];
      |        ^~~~~~~
# 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
4 Correct 0 ms 348 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 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 8 ms 2140 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 14 ms 3932 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 18 ms 4636 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 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 5 ms 604 KB Output is correct
8 Correct 14 ms 3964 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 18 ms 4552 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1624 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1624 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1624 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 7 ms 2140 KB Output is correct
12 Correct 7 ms 2136 KB Output is correct
13 Correct 8 ms 2140 KB Output is correct
14 Correct 7 ms 1988 KB Output is correct
15 Correct 12 ms 2396 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 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
4 Correct 0 ms 412 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 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 348 KB Output is correct
2 Correct 0 ms 348 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 1 ms 348 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 39 ms 4180 KB Output is correct
10 Correct 31 ms 3420 KB Output is correct
11 Correct 10 ms 1372 KB Output is correct
12 Correct 13 ms 1740 KB Output is correct
13 Incorrect 3 ms 604 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 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
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 41 ms 4012 KB Output is correct
10 Correct 32 ms 3416 KB Output is correct
11 Correct 10 ms 1372 KB Output is correct
12 Correct 16 ms 1840 KB Output is correct
13 Incorrect 3 ms 856 KB Output isn't correct
14 Halted 0 ms 0 KB -