답안 #1015345

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015345 2024-07-06T08:56:28 Z amirhoseinfar1385 곤돌라 (IOI14_gondola) C++17
100 / 100
42 ms 6084 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
int inf=1e9+5,mod=1e9+9;
long long mypow(long long m,long long y){
  if(y==0){
    return 1;
  }
  long long p=mypow(m,(y>>1));
  p*=p;
  p%=mod;
  if(y&1){
    p*=m;
    p%=mod;
  }
  return p;
}


int fas(int u,int v,int n){
  //cout<<u<<" "<<v<<" "<<(u-v+n+n)%n<<endl;
  return (u-v+n+n)%n;
}

int valid(int n, int inputSeq[])
{
  set<int>st;
  int wh=-1,mn=inf;
  for(int i=0;i<n;i++){
    if(inputSeq[i]<mn){
      wh=i;
      mn=inputSeq[i];
    }
    if(st.count(inputSeq[i])==1){
      return 0;
    }
    st.insert(inputSeq[i]);
  }
  int last=mn,lastwh=wh;
  for(int i=0;i<n;i++){
    if(inputSeq[(i+wh)%n]<=n){
      if(inputSeq[(i+wh)%n]!=(mn+i)){
        return 0;
      }
      lastwh=(i+wh)%n;
      last=inputSeq[(i+wh)%n];
    }
  }
  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  set<pair<int,int>>st;
  int wh=-1,mn=inf;
  for(int i=0;i<n;i++){
    if(gondolaSeq[i]<mn){
      wh=i;
      mn=gondolaSeq[i];
    }
  }
  wh=wh-mn+1;
  while(wh<0){
    wh+=n;
  }
  wh%=n;
  for(int i=0;i<n;i++){
    st.insert(make_pair(gondolaSeq[(wh+i)%n],i+1));
  }
  int now=n+1;
  vector<int>all(n+1);
  for(int i=1;i<=n;i++){
    all[i]=i;
  }
  while((int)st.size()>0){
    auto x=(*st.begin());
    st.erase(x);
    while(now<=x.first){
      replacementSeq[now-(n+1)]=all[x.second];
      all[x.second]=now;
      now++;   
    }
  }
  return (now-(n+1));
}

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

int countReplacement(int n, int inputSeq[])
{
  if(valid(n,inputSeq)==0){
    return 0;
  }
  vector<int>all;
  long long mn=inf;
  for(int i=0;i<n;i++){
    inf=min(inf,inputSeq[i]);
    if(inputSeq[i]>n){
      all.push_back(inputSeq[i]);
    }
  }
  all.push_back(n);
  sort(all.begin(),all.end());
  long long mainres=1;
  for(int i=1;i<(int)all.size();i++){
 //   cout<<"salam: "<<i<<endl;
    mainres*=mypow((all.size()-i),all[i]-all[i-1]-1);
    mainres%=mod;
   // cout<<"by"<<endl;
  }
  if(inf>n){
    mainres*=n;
    mainres%=mod;
  }
  return mainres;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:39:7: warning: variable 'last' set but not used [-Wunused-but-set-variable]
   39 |   int last=mn,lastwh=wh;
      |       ^~~~
gondola.cpp:39:15: warning: variable 'lastwh' set but not used [-Wunused-but-set-variable]
   39 |   int last=mn,lastwh=wh;
      |               ^~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:97:13: warning: unused variable 'mn' [-Wunused-variable]
   97 |   long long mn=inf;
      |             ^~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
6 Correct 9 ms 2120 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 17 ms 3932 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 22 ms 4612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 9 ms 2140 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 20 ms 3932 KB Output is correct
9 Correct 6 ms 1372 KB Output is correct
10 Correct 24 ms 4544 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 12 ms 2100 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 30 ms 4760 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 344 KB Output is correct
5 Correct 0 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 344 KB Output is correct
5 Correct 0 ms 348 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 476 KB Output is correct
9 Correct 0 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 356 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 21 ms 4652 KB Output is correct
12 Correct 22 ms 5208 KB Output is correct
13 Correct 22 ms 2772 KB Output is correct
14 Correct 19 ms 4696 KB Output is correct
15 Correct 14 ms 2908 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
# 결과 실행 시간 메모리 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 344 KB Output is correct
5 Correct 1 ms 604 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
# 결과 실행 시간 메모리 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 29 ms 4444 KB Output is correct
10 Correct 24 ms 3676 KB Output is correct
11 Correct 7 ms 1740 KB Output is correct
12 Correct 9 ms 1788 KB Output is correct
13 Correct 3 ms 1120 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 352 KB Output is correct
4 Correct 0 ms 352 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 356 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 29 ms 4436 KB Output is correct
10 Correct 28 ms 3740 KB Output is correct
11 Correct 8 ms 1624 KB Output is correct
12 Correct 10 ms 1884 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 38 ms 5340 KB Output is correct
15 Correct 42 ms 6084 KB Output is correct
16 Correct 6 ms 1372 KB Output is correct
17 Correct 27 ms 4140 KB Output is correct
18 Correct 15 ms 2396 KB Output is correct