답안 #489294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489294 2021-11-22T04:26:16 Z QuantumK9 곤돌라 (IOI14_gondola) C++17
60 / 100
31 ms 4504 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

int valid(int n, int inputSeq[]){

  ll mx = n;

  set<ll> memo;

  ll i = 0;
  ll expectedVal;
  while ( i < n ){

    ll use = inputSeq[i];
    i++;

    if ( memo.find(use) != memo.end() ){ return 0; }

    memo.insert( use );

    mx = max( mx, use );

    if ( use <= n ){ expectedVal = use; break; }
    
  }

  for ( ; i < n; i++ ){

    expectedVal++; if( expectedVal > n ){ expectedVal -= n; }

    //cout << inputSeq[i] << " " << expectedVal << endl;

    ll use = inputSeq[i];

    if ( use <= n ){
      if ( use != expectedVal ){ return 0; }
    }
    
    if ( memo.find(use) != memo.end() ){ return 0; }
    memo.insert( use );
    mx = max( mx, use );

  }

  //for( ll j = n+1; j <= mx; j++ ){ if ( memo.find(j) == memo.end() ){ return 0; } }


  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
  
  vector< pair<ll, ll> > makeAyos;  // newVal, expectedVal

  ll i = 0;

  ll expectedVal = -1;

  while ( i < n ){
    ll u = gondolaSeq[i];

    if ( u <= n ){ expectedVal = u; break; }

    i++;
  }

  // case 1 -- > at least one default value remains
  if ( expectedVal != -1 ){
    expectedVal -= i;
    if ( expectedVal <= 0 ){ expectedVal += n; }
  }
  // case 2 -- > no more default values remain
  else{
    expectedVal = 1;
  }

  //cout << "ev: " << expectedVal << endl;

  for( int j = 0; j < n; j++ ){

    if ( gondolaSeq[j] != expectedVal ){
      makeAyos.pb ( mp( gondolaSeq[j], expectedVal ) );
    }

    expectedVal++; if ( expectedVal > n ){ expectedVal -= n; }
  }

  sort( makeAyos.begin(), makeAyos.end());

  // for( int l = 0; l < makeAyos.size(); l++ ){
  //   cout << makeAyos[l].first << " " << makeAyos[l].second << endl;
  // }

  ll cnt = 0;

  ll replacementVal = n+1;

  for( int k = 0; k < makeAyos.size(); k++ ){

    // at least one do-up
    replacementSeq[ cnt ] = makeAyos[k].second;
    cnt++;
    replacementVal++;

    while ( replacementVal <= makeAyos[k].first ){

      replacementSeq[ cnt ] = replacementVal-1;

      cnt++;

      replacementVal++;

    }

  }

  return cnt;

}

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

const ll MOD = 1000000007;

ll mod_pow( ll b, ll e ){

  if ( e == 0 ){ return 1; }
  if ( e == 1 ){ return b; }

  if ( e%2 ){ return (b*( mod_pow(b,e-1) )%MOD)%MOD; }
  else{ return mod_pow( (b*b)%MOD, e/2 )%MOD; }
}

ll solve( ll n, ll s, vector<ll> v ){

  ll fA = 1, cV = n;

  for( int i = 0; i < s; i++ ){

    ll daDistance = v[i] - cV;
    daDistance--;

    fA *= mod_pow( s-i, daDistance );
    fA %= MOD;

    cV = v[i];

    //cout << v[i] << " " << fA << endl;

  }

  return fA;
}

int countReplacement(int n, int inputSeq[]){

  if ( !valid(n, inputSeq) ){ return 0; }

  ll i = 0, expectedVal = -1;

  while ( i < n ){
    if ( inputSeq[i] <= n ){ expectedVal = inputSeq[i]; break; }
    i++;
  }

  // case 1 -- > at least one default value remains
  if ( expectedVal != -1 ){

    expectedVal -= i;
    if ( expectedVal <= 0 ){ expectedVal += n; }

    vector<ll> toSolve;

    for( int j = 0; j < n; j++ ){

      if ( inputSeq[j] != expectedVal ){ toSolve.pb ( inputSeq[j] ); }

      expectedVal++; 
      if ( expectedVal > n ){ expectedVal -= n; }

    }

    sort( toSolve.begin(), toSolve.end() );

    return solve( n, toSolve.size(), toSolve );

  }

  // case 2 -- > no more default values remain
  else{
    
    // for all expectedVal { 1 , n } --> solve
    return -3;

  }

}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:105:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |   for( int k = 0; k < makeAyos.size(); k++ ){
      |                   ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 12 ms 2124 KB Output is correct
7 Correct 7 ms 620 KB Output is correct
8 Correct 21 ms 3816 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 31 ms 4468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 11 ms 2124 KB Output is correct
7 Correct 7 ms 588 KB Output is correct
8 Correct 20 ms 3824 KB Output is correct
9 Correct 7 ms 1356 KB Output is correct
10 Correct 28 ms 4504 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 3 ms 332 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 6 ms 588 KB Output is correct
12 Correct 7 ms 588 KB Output is correct
13 Correct 14 ms 1304 KB Output is correct
14 Correct 7 ms 588 KB Output is correct
15 Correct 17 ms 2236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Incorrect 0 ms 208 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 0 ms 208 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 236 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Incorrect 0 ms 300 KB Output isn't correct
8 Halted 0 ms 0 KB -