답안 #285530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285530 2020-08-29T08:15:31 Z erd1 곤돌라 (IOI14_gondola) C++14
100 / 100
81 ms 6052 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;
typedef long double ld;

int valid(int n, int inputSeq[]) {
  set<int> uses;
  for(int i = 0; i < n; i++)if(inputSeq[i] <= n){
    rotate(inputSeq, inputSeq+i, inputSeq+n);
    if(inputSeq[0] != 1) rotate(inputSeq, inputSeq + (n-inputSeq[0]+1), inputSeq + n);
    break;
  }
  for(int i = 0; i < n; i++)
    if(inputSeq[i] == i+1) continue;
    else if(inputSeq[i] <= n)return 0; else if(uses.count(inputSeq[i])) return 0; else uses.insert(inputSeq[i]);
  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
  map<int, int> mp;
  for(int i = 0; i < n; i++)if(gondolaSeq[i] <= n){
    rotate(gondolaSeq, gondolaSeq+i, gondolaSeq+n);
    if(gondolaSeq[0] != 1) rotate(gondolaSeq, gondolaSeq + (n-gondolaSeq[0]+1), gondolaSeq + n);
    break;
  }
  for(int i = 0; i < n; i++)if(gondolaSeq[i] > n)mp[gondolaSeq[i]] = i+1;
  int cur = 0;
  for(auto i: mp){
    int l = i.ss;
    while(cur+n < i.ff)
      replacementSeq[cur++] = l, l = n+cur;
  }
  return cur;
}

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

const int mod = 1000000009;
inline int fpow(lld a, int b){
  lld ans = 1;
  do if(b&1) ans = ans*a%mod;
  while(a = a*a%mod, b>>=1);
  return (int)ans;
}

int countReplacement(int n, int inputSeq[]) {
  vector<int> v;
  if(!valid(n, inputSeq))return 0;
  for(int i = 0; i < n; i++)if(inputSeq[i] > n)v.pb(inputSeq[i]);
  sort(all(v));
  lld ans = 1;
  for(int i = 0; i < (int)v.size(); i++)
    ans = ans*fpow((int)v.size()-i, (v[i]-(i?v[i-1]:n)-1))%mod;
  return (int)(ans*((int)v.size() == n? n:1)%mod);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 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 512 KB Output is correct
7 Correct 17 ms 680 KB Output is correct
8 Correct 16 ms 640 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 15 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 14 ms 640 KB Output is correct
8 Correct 11 ms 640 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 13 ms 640 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 8 ms 512 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 15 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 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 256 KB Output is correct
6 Correct 0 ms 256 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 256 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
6 Correct 0 ms 256 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 12 ms 640 KB Output is correct
12 Correct 14 ms 768 KB Output is correct
13 Correct 25 ms 2552 KB Output is correct
14 Correct 13 ms 768 KB Output is correct
15 Correct 29 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 384 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 0 ms 256 KB Output is correct
5 Correct 1 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 384 KB Output is correct
9 Correct 46 ms 3836 KB Output is correct
10 Correct 33 ms 2944 KB Output is correct
11 Correct 15 ms 1536 KB Output is correct
12 Correct 18 ms 1792 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 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 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 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 44 ms 3832 KB Output is correct
10 Correct 33 ms 2940 KB Output is correct
11 Correct 15 ms 1588 KB Output is correct
12 Correct 18 ms 1792 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 73 ms 5468 KB Output is correct
15 Correct 81 ms 6052 KB Output is correct
16 Correct 14 ms 1408 KB Output is correct
17 Correct 49 ms 4216 KB Output is correct
18 Correct 27 ms 2432 KB Output is correct