답안 #1064515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064515 2024-08-18T13:46:46 Z VMaksimoski008 곤돌라 (IOI14_gondola) C++17
100 / 100
42 ms 6480 KB
#include "gondola.h"
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int mod = 1e9 + 9;
 
int valid(int n, int inputSeq[]) {
    int ans = 1;
    int cnt = 0;
    set<int> s;
 
    int big = 0;
    for(int i=0; i<n; i++) {
      if(inputSeq[i] > n) big++;
    }
 
    vector<int> v(n);
    int pos = -1;
    for(int i=0; i<n; i++) {
      if(inputSeq[i] <= n) {
        pos = i;
        v[i] = inputSeq[i];
        break;
      }
    }
 
    for(int i=pos+1; i<n; i++) {
      v[i] = v[i-1] + 1;
      //if(v[i] > n) v[i] -= n;
    }
 
    for(int i=pos-1; i>=0; i--) {
      v[i] = v[i+1] - 1;
      //if(v[i] <= 0) 
    }
 
    for(int i=0; i<n; i++) {
      if(v[i] > n) v[i] -= n;
      else if(v[i] <= 0) v[i] += n;
    }
 
    for(int i=0; i<n; i++) {
      if(inputSeq[i] > n) continue;
      if(inputSeq[i] != v[i]) return 0;
    }
 
    for(int i=0; i<n; i++) s.insert(inputSeq[i]);
    if(s.size() < n) return 0;
 
    return 1;
}
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
  int cnt = 0, big = 0, arr[n];
  for(int i=0; i<n; i++) arr[i] = gondolaSeq[i];
 
  for(int i=0; i<n; i++) big += (arr[i] > n);
 
  if(big == n) {
    vector<pair<int, int> > v;
    for(int i=0; i<n; i++) v.push_back({ arr[i], i + 1 });
    sort(v.begin(), v.end());
 
    int curr = n + 1;
    for(int i=0; i<n; i++) {
      int a = v[i].second, b = v[i].first;
      replacementSeq[cnt++] = a;
      while(curr != b) {
        replacementSeq[cnt++] = curr++;
      }
      curr++;
    }
  } else {
    vector<int> v(n);
    int pos = -1;
    for(int i=0; i<n; i++) {
      if(arr[i] <= n) {
        pos = i;
        v[i] = arr[i];
        break;
      }
    }
 
    for(int i=pos+1; i<n; i++) v[i] = v[i-1] + 1;
    for(int i=pos-1; i>=0; i--) v[i] = v[i+1] - 1;
 
    for(int i=0; i<n; i++) {
      if(v[i] > n) v[i] -= n;
      else if(v[i] <= 0) v[i] += n;
    }
 
    vector<pair<int, int> > ord;
    for(int i=0; i<n; i++) 
      if(arr[i] > n) ord.push_back({ arr[i], v[i] });
    sort(ord.begin(), ord.end());
 
    int curr = n + 1;
    for(auto &[b, a] : ord) {
      replacementSeq[cnt++] = a;
      while(curr != b) replacementSeq[cnt++] = curr++;
      curr++;
    }
  }
 
  return cnt;
}
 
ll exp(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return ans;
}
 
int countReplacement(int n, int inputSeq[]) {
  if(!valid(n, inputSeq)) return 0;
  ll ans = 1;
 
  vector<int> v;
  for(int i=0; i<n; i++)
    if(inputSeq[i] > n) v.push_back(inputSeq[i]);
  if(v.size() == 0) return 1;
  sort(v.begin(), v.end());
 
  int mx = v.back();
  int sz = v.size();
  ll curr = n + 1;
  for(int i=0; i<sz; i++) {
    ans = (ans * exp(sz - i, v[i] - curr + ((sz - i) == n))) % mod;
    curr = v[i] + 1;
  }
 
  return (int)ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:49:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |     if(s.size() < n) return 0;
      |        ~~~~~~~~~^~~
gondola.cpp:9:9: warning: unused variable 'ans' [-Wunused-variable]
    9 |     int ans = 1;
      |         ^~~
gondola.cpp:10:9: warning: unused variable 'cnt' [-Wunused-variable]
   10 |     int cnt = 0;
      |         ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:129:7: warning: unused variable 'mx' [-Wunused-variable]
  129 |   int mx = v.back();
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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
6 Correct 8 ms 2324 KB Output is correct
7 Correct 5 ms 1116 KB Output is correct
8 Correct 14 ms 4188 KB Output is correct
9 Correct 5 ms 1628 KB Output is correct
10 Correct 18 ms 4956 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 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 2396 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 16 ms 4224 KB Output is correct
9 Correct 5 ms 1628 KB Output is correct
10 Correct 19 ms 4844 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 ms 948 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 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 388 KB Output is correct
4 Correct 1 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 348 KB Output is correct
9 Correct 0 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 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
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 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 348 KB Output is correct
11 Correct 5 ms 1760 KB Output is correct
12 Correct 6 ms 1880 KB Output is correct
13 Correct 9 ms 1696 KB Output is correct
14 Correct 6 ms 1628 KB Output is correct
15 Correct 13 ms 2492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 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 440 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 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 1 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 1 ms 348 KB Output is correct
5 Correct 0 ms 440 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
9 Correct 29 ms 4808 KB Output is correct
10 Correct 21 ms 4008 KB Output is correct
11 Correct 7 ms 1628 KB Output is correct
12 Correct 10 ms 2052 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 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
9 Correct 29 ms 4928 KB Output is correct
10 Correct 20 ms 4064 KB Output is correct
11 Correct 7 ms 1628 KB Output is correct
12 Correct 9 ms 2104 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 37 ms 5636 KB Output is correct
15 Correct 42 ms 6480 KB Output is correct
16 Correct 8 ms 1372 KB Output is correct
17 Correct 24 ms 4532 KB Output is correct
18 Correct 13 ms 2652 KB Output is correct