답안 #409098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409098 2021-05-20T08:01:54 Z pliam 곤돌라 (IOI14_gondola) C++14
100 / 100
35 ms 3752 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000009
typedef long long ll;
//valid
vector<pair<int,int>> input;//(val,id)
vector<pair<int,int>> rep;//(val,id)
vector<ll> ext;//val (only)

int valid(int n, int inputSeq[])
{
  input.clear();
  for(int i=0;i<n;i++){
    input.push_back({inputSeq[i],i});
  }
  sort(input.begin(),input.end());
  int prev=-1;
  for(int i=0;i<n;i++){
    if(input[i].first==prev) return 0;
    prev=input[i].first;
  }
  int prev_pos=-1;
  for(int i=0;i<n&&input[i].first<=n;i++){
    if((i!=0)&&((input[i].first-prev)!=((input[i].second-prev_pos+n)%n))){
      return 0;
    }
    prev=input[i].first;
    prev_pos=input[i].second;
  }
  return 1;
}

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

int mod1(int x,int m){
  x%=m;
  if(x==0) x=m;
  return x;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  rep.clear();
  int extra=0;
  for(int i=0;i<n;i++){
    if(gondolaSeq[i]>n) rep.push_back({gondolaSeq[i],i});
    else extra=(gondolaSeq[i]-i+n)%n;
  }
  for(auto& p:rep){
    p.second+=extra;
    p.second=mod1(p.second,n);
  }
  sort(rep.begin(),rep.end());
  int l=0;
  int prev=n;
  for(auto p:rep){
    replacementSeq[l]=p.second;
    l++;
    for(int i=prev+1;i<p.first;i++){
      replacementSeq[l]=i;
      l++;
    }
    prev=p.first;
  }
  return l;
}

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

ll binpow(ll a,ll b){
  ll ans=1;
  while(b>0){
    if(b&1) ans=(ans*a)%MOD;
    a=(a*a)%MOD;
    b/=2;
  }
  return ans;
}

int countReplacement(int n, int inputSeq[])
{
  ext.clear();
  if(!valid(n,inputSeq)) return 0;
  for(int i=0;i<n;i++){
    if(inputSeq[i]>n) ext.push_back(inputSeq[i]);
  }
  sort(ext.begin(),ext.end());
  ll prev=n;
  ll res=1;
  for(int i=0;i<ext.size();i++){
    res=(res*binpow(ext.size()-i,ext[i]-prev-1))%MOD;
    prev=ext[i];
  }
  /*
  if(ext.size()==n){//multiply by n!
    for(int i=1;i<=n;i++){
      res=(res*i)%MOD;
    }
  }
  */

  if(ext.size()==n) res=(res*n)%MOD;
  
  return res;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:91:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   for(int i=0;i<ext.size();i++){
      |               ~^~~~~~~~~~~
gondola.cpp:103:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  103 |   if(ext.size()==n) res=(res*n)%MOD;
      |      ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 8 ms 1208 KB Output is correct
7 Correct 19 ms 2280 KB Output is correct
8 Correct 13 ms 2072 KB Output is correct
9 Correct 6 ms 844 KB Output is correct
10 Correct 18 ms 2328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 8 ms 1224 KB Output is correct
7 Correct 19 ms 2236 KB Output is correct
8 Correct 13 ms 2084 KB Output is correct
9 Correct 6 ms 876 KB Output is correct
10 Correct 18 ms 2220 KB Output is correct
11 Correct 1 ms 296 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 9 ms 1308 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 19 ms 2244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 280 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 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 12 ms 952 KB Output is correct
12 Correct 11 ms 1056 KB Output is correct
13 Correct 16 ms 1708 KB Output is correct
14 Correct 10 ms 972 KB Output is correct
15 Correct 24 ms 2420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 27 ms 2604 KB Output is correct
10 Correct 22 ms 2116 KB Output is correct
11 Correct 8 ms 1124 KB Output is correct
12 Correct 11 ms 1100 KB Output is correct
13 Correct 3 ms 444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 288 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 23 ms 2560 KB Output is correct
10 Correct 19 ms 2048 KB Output is correct
11 Correct 8 ms 1088 KB Output is correct
12 Correct 9 ms 1100 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 32 ms 3556 KB Output is correct
15 Correct 35 ms 3752 KB Output is correct
16 Correct 6 ms 968 KB Output is correct
17 Correct 22 ms 2372 KB Output is correct
18 Correct 14 ms 1844 KB Output is correct