답안 #991834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991834 2024-06-03T08:30:33 Z huutuan 곤돌라 (IOI14_gondola) C++14
75 / 100
41 ms 4656 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];
      |        ^~~~~~~
# 결과 실행 시간 메모리 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 1 ms 348 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 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 8 ms 2140 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 14 ms 3932 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 22 ms 4608 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 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 8 ms 2140 KB Output is correct
7 Correct 10 ms 600 KB Output is correct
8 Correct 15 ms 4076 KB Output is correct
9 Correct 5 ms 1372 KB Output is correct
10 Correct 22 ms 4440 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 5 ms 536 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 6 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1624 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 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 1628 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1632 KB Output is correct
8 Correct 1 ms 1624 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 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 1372 KB Output is correct
5 Correct 1 ms 1372 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 1628 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 6 ms 2216 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 2140 KB Output is correct
15 Correct 22 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 376 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 1 ms 348 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 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 444 KB Output is correct
8 Correct 0 ms 444 KB Output is correct
9 Correct 41 ms 4444 KB Output is correct
10 Correct 32 ms 3928 KB Output is correct
11 Correct 10 ms 1624 KB Output is correct
12 Correct 13 ms 1884 KB Output is correct
13 Incorrect 3 ms 604 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 39 ms 4656 KB Output is correct
10 Correct 32 ms 3676 KB Output is correct
11 Correct 11 ms 1628 KB Output is correct
12 Correct 13 ms 1880 KB Output is correct
13 Incorrect 5 ms 600 KB Output isn't correct
14 Halted 0 ms 0 KB -