답안 #1005812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005812 2024-06-23T05:47:58 Z Gray 곤돌라 (IOI14_gondola) C++17
75 / 100
35 ms 6816 KB
#include<bits/stdc++.h>
#include "gondola.h"
#define ll long long
#define ff first
#define ss second
#define ln "\n"

using namespace std;
const ll MOD = 1e9+9;

int valid(int n, int inputSeq[])
{
  vector<ll> sn(n);
  ll trunk=-1;
  map<ll, ll> usd;
  for (ll i=0; i<n; i++){
    if (usd[inputSeq[i]]) return 0;
    usd[inputSeq[i]]=1;
    if (inputSeq[i]<=n) {
      sn[i]=inputSeq[i];
      trunk=i;
    }
  }
  if (trunk==-1) return 1;
  ll init = inputSeq[trunk]-1;
  for (ll i=trunk-1; i>=0; i--){
    sn[i]=(--init+n)%n+1;
  }
  init=inputSeq[trunk]-1;
  for (ll i=trunk+1; i<n; i++){
    sn[i]=(++init)%n+1;
  }
  for (ll i=0; i<n; i++){
    if (inputSeq[i]<=n and inputSeq[i]!=sn[i]) return 0;
  }
  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  vector<ll> sn(n);
  ll trunk=-1;
  for (ll i=0; i<n; i++){
    if (gondolaSeq[i]<=n) {
      sn[i]=gondolaSeq[i];
      trunk=i;
    }
  }
  ll init = gondolaSeq[trunk]-1;
  for (ll i=trunk-1; i>=0; i--){
    sn[i]=(--init+n)%n+1;
  }
  init=gondolaSeq[trunk]-1;
  for (ll i=trunk+1; i<n; i++){
    sn[i]=(++init)%n+1;
  }
  vector<pair<ll, ll>> rep;
  for (ll i=0; i<n; i++){
    if (gondolaSeq[i]>n){
      rep.push_back({gondolaSeq[i], sn[i]});
    }
  }
  sort(rep.begin(), rep.end());
  ll len=0, prev=n, last;
  for (ll i=0; i<(ll)rep.size(); i++){
    // cout << rep[i].ff << " " << rep[i].ss << ln;
    last=rep[i].ss;
    while (prev<rep[i].ff){
      replacementSeq[len]=last;
      len++;
      last=++prev;
    } 
  }
  return len;
}

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

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

int countReplacement(int n, int inputSeq[])
{
  if (!valid(n, inputSeq)) return 0;
  vector<ll> sn(n);
  ll trunk=-1;
  for (ll i=0; i<n; i++){
    if (inputSeq[i]<=n) {
      sn[i]=inputSeq[i];
      trunk=i;
    }
  }
  ll init = inputSeq[trunk]-1;
  for (ll i=trunk-1; i>=0; i--){
    sn[i]=(--init+n)%n+1;
  }
  init=inputSeq[trunk]-1;
  for (ll i=trunk+1; i<n; i++){
    sn[i]=(++init)%n+1;
  }
  vector<pair<ll, ll>> rep;
  for (ll i=0; i<n; i++){
    if (inputSeq[i]>n){
      rep.push_back({inputSeq[i], sn[i]});
    }
  }
  sort(rep.begin(), rep.end());
  ll prev=n;
  ll ans=1;
  for (ll i=0; i<(ll)rep.size(); i++){
    ans=ans*binpow(rep.size()-i, rep[i].ff-prev-1)%MOD;
    // cout << "H: " << rep.size()-i << "^" <<  rep[i].ff-prev-1 << "->" << binpow(rep.size()-i, rep[i].ff-prev-1) << ln;
    prev=rep[i].ff;
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 344 KB Output is correct
2 Correct 1 ms 344 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 12 ms 3164 KB Output is correct
7 Correct 6 ms 1368 KB Output is correct
8 Correct 24 ms 5724 KB Output is correct
9 Correct 7 ms 2140 KB Output is correct
10 Correct 31 ms 6740 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 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 11 ms 3096 KB Output is correct
7 Correct 6 ms 1372 KB Output is correct
8 Correct 23 ms 5584 KB Output is correct
9 Correct 6 ms 2140 KB Output is correct
10 Correct 27 ms 6584 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 14 ms 2904 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 35 ms 6816 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 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 1 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 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 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 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 5 ms 1372 KB Output is correct
12 Correct 6 ms 1308 KB Output is correct
13 Correct 10 ms 1496 KB Output is correct
14 Correct 6 ms 1116 KB Output is correct
15 Correct 12 ms 2376 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 440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 600 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 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 448 KB Output is correct
7 Correct 0 ms 444 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 35 ms 6268 KB Output is correct
10 Correct 28 ms 5212 KB Output is correct
11 Correct 10 ms 2136 KB Output is correct
12 Correct 13 ms 2640 KB Output is correct
13 Incorrect 3 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 420 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 0 ms 440 KB Output is correct
9 Correct 35 ms 6232 KB Output is correct
10 Correct 31 ms 5212 KB Output is correct
11 Correct 11 ms 2392 KB Output is correct
12 Correct 13 ms 2692 KB Output is correct
13 Incorrect 3 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -