답안 #308189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308189 2020-09-30T08:46:12 Z kylych03 곤돌라 (IOI14_gondola) C++14
100 / 100
80 ms 6008 KB
#include "gondola.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
int vis[1000001];
int res1[1000001];
pair <int, int> arr[1000001];
long long x[1000001];
long long mod = 1e9+9;
map <int, int> vis1;
long long binpow (long long a, long long b) {
	if (b == 0)
		return 1;
	if (b % 2 == 1)
		return binpow (a, b-1) * 1ll *  a % mod;
	else {
		int c = binpow (a, b/2);
		return c * 1ll *  c % mod;
	}
}
int valid(int n, int inputSeq[])
{
    int ind = 0;
    int num = 0;
  for(int i = 0 ; i< n ; i++){
    if(inputSeq[i]>=1 && inputSeq[i] <=n ){
        ind = i;
        num = inputSeq[i];
    }
    if(inputSeq[i] <1)
        return 0;
    if(vis[inputSeq[i]] ==1)
        return 0;

    vis[inputSeq[i]]=1;

  }
  if(num==0)
    return 1;
  for(int i = 0 ; i < n; i++)
  if(inputSeq[i] <= n){
    if( (ind  +  (inputSeq[i] - num)  +n ) %n!=i  )
        return 0;
  }
  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int mx = 0;
    int mxind=0;
    int ind = 0;
    int num = 0;
    int cnt = 0;
    for(int i = 0 ; i < n; i++){
        arr[i] = make_pair(gondolaSeq[i] , i+1);
        vis[gondolaSeq[i]]=1;
        if( gondolaSeq[i]>=1 && gondolaSeq[i] <=n ){
            ind = i+1;
            num = gondolaSeq[i];
        }
        if ( mx <  gondolaSeq[i]){
            mx =  gondolaSeq[i];
            mxind =i;
        }
    }
    sort(arr, arr + n);

    if(num == 0){
        vector <int > vec;
        for(int i = mx-1; i>n;i--){
            if(vis[i]==0)
                vec.push_back(i);
        }

        for(int i= 0; i < n ;i++){
            int t = arr[i].second;
            int p = arr[i].first;
            replacementSeq[cnt]=t;
            cnt ++;
                while( vec.size () >  0 && p > vec.back()){
                    replacementSeq[cnt]=vec.back();
                    cnt ++;
                    vec.pop_back();
                }
            }
        return mx - n;
    }
    for(int i =1; i <=n ;i++){
        res1[i-1] = (num + i -ind + n)%n ;
        if(res1[i-1]==0)
            res1[i-1]=n;
    }
    vector <int > vec;
    for(int i = mx-1; i>n;i--){
        if(vis[i]==0)
            vec.push_back(i);
    }
    for(int i =0 ; i <n;i++){
        int t = arr[i].second;
        int p = arr[i].first;
        if(gondolaSeq[t-1]!=res1[t-1]){
            replacementSeq[cnt]=res1[t-1];
            cnt ++;
            while( vec.size () >  0 && gondolaSeq[t-1] > vec.back()){
                replacementSeq[cnt]=vec.back();
                cnt ++;
                vec.pop_back();
            }
        }
    }

  return mx - n;
}

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

int countReplacement(int n, int inputSeq[])
{
  int ind = 0;
    int num = 0;
  for(int i = 0 ; i< n ; i++){
    if(inputSeq[i]>=1 && inputSeq[i] <=n ){
        ind = i;
        num = inputSeq[i];
    }
    if(inputSeq[i] <1)
        return 0;
    if(vis1[inputSeq[i]] ==1)
        return 0;

    vis1[inputSeq[i]]=1;

  }
  if(num!=0)
  for(int i = 0 ; i < n; i++)
  if(inputSeq[i] <= n){
    if( (ind  +  (inputSeq[i] - num)  +n ) %n!=i  )
        return 0;
  }
  sort(inputSeq, inputSeq + n);
  for(int i = 0 ; i < n; i++)
    x[i] = inputSeq[i];
 bool f=true;
 long long res=  1;
  for(int i = 0; i < n ; i++ ){
    if(x[i] > n){
        if(f){
            res = res  * 1ll * binpow( (n- i), (x[i] - n - 1) ) % mod;
        }
        else{
            res = res   * 1ll * binpow( (n- i), x[i] - x[i-1] - 1) % mod;
        }
        f=false;
    }
  }
  if(x[0] > n)
    res = res * 1ll * n % mod;
  return res;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:103:13: warning: unused variable 'p' [-Wunused-variable]
  103 |         int p = arr[i].first;
      |             ^
gondola.cpp:53:9: warning: variable 'mxind' set but not used [-Wunused-but-set-variable]
   53 |     int mxind=0;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 13 ms 1024 KB Output is correct
8 Correct 13 ms 896 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 12 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 13 ms 1024 KB Output is correct
8 Correct 11 ms 896 KB Output is correct
9 Correct 4 ms 512 KB Output is correct
10 Correct 12 ms 1024 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 7 ms 1280 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 14 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 16 ms 1920 KB Output is correct
12 Correct 17 ms 2048 KB Output is correct
13 Correct 18 ms 2136 KB Output is correct
14 Correct 14 ms 1920 KB Output is correct
15 Correct 26 ms 2972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 52 ms 4600 KB Output is correct
10 Correct 40 ms 3832 KB Output is correct
11 Correct 14 ms 1664 KB Output is correct
12 Correct 18 ms 1920 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 52 ms 4600 KB Output is correct
10 Correct 43 ms 3960 KB Output is correct
11 Correct 15 ms 1664 KB Output is correct
12 Correct 18 ms 1920 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 65 ms 5240 KB Output is correct
15 Correct 80 ms 6008 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 47 ms 4088 KB Output is correct
18 Correct 25 ms 2424 KB Output is correct