답안 #793885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793885 2023-07-26T07:51:21 Z Ronin13 곤돌라 (IOI14_gondola) C++17
100 / 100
45 ms 6012 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

const ll mod = 1e9 + 9;

int valid(int n, int a[]){
    vector <pii> vv;
    set <int> st;
    for(int i = 0; i < n; i++){
      if(st.find(a[i]) != st.end())
        return 0;
      st.insert(a[i]);
        if(a[i] <= n)
          vv.pb({a[i], i});
    }
    sort(vv.begin(), vv.end());
    for(int i = 1; i < vv.size(); i++){
      int x = vv[i].s, y = vv[i - 1].s;
      int dist = vv[i].f - vv[i - 1].f;
      if((x - y + n) % n != dist)
        return 0;
    }
    return 1;
}

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

int replacement(int n, int a[], int b[])
{
  int c[n];

  int cur = n + 1;
  int ind = 0;
  vector <pii> vv;
  int x, y;
  for(int i = 0; i < n; i++){
    if(a[i] > n) vv.pb({a[i], i});
    else x = a[i], y = i;
  }
  if(vv.size() == n){
      for(int i = 0; i < n; i++) c[i] = i + 1;
  }
  else{
      for(int i = 0; i < n; i++){
        int dist = (i - y + n) % n;
        c[i] = (x + dist - 1) % n + 1;
      }
  }
  sort(vv.begin(), vv.end());
  for(int i = 0; i < vv.size(); i++){
    while(cur <= vv[i].f)
      b[ind] = c[vv[i].s], c[vv[i].s] = cur, ind++, cur++;
  }
  return ind;
}

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


ll logpow(ll a, ll p){
  if(p == 0)
  return 1;
  ll x = logpow(a, p / 2);
  x *= x, x %= mod;
  if(p & 1) x *= a, x %= mod;
  return x;
}

int countReplacement(int n, int a[])
{
  if(!valid(n, a))
    return 0;
  vector <int> vv;
  int cnt = 0;
  for(int i = 0; i < n; i++){
      if(a[i] > n) cnt++, vv.pb(a[i]);
  }
  bool x = (cnt == n);
  sort(vv.begin(), vv.end());
  int last = n;
  ll ans = 1;
  for(int i = 0; i < vv.size(); i++){
      int c = vv[i] - last - 1;
      ans *= logpow(cnt, c);
      cnt--;
      ans %= mod;
      last = vv[i];
  }
  if(x) ans *= (ll)n, ans %= mod;
  return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 1; i < vv.size(); i++){
      |                    ~~^~~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:49:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |   if(vv.size() == n){
      |      ~~~~~~~~~~^~~~
gondola.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i = 0; i < vv.size(); i++){
      |                  ~~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   for(int i = 0; i < vv.size(); i++){
      |                  ~~^~~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:44:10: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   int x, y;
      |          ^
gondola.cpp:55:19: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |         c[i] = (x + dist - 1) % n + 1;
      |                 ~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 2456 KB Output is correct
7 Correct 6 ms 584 KB Output is correct
8 Correct 22 ms 4684 KB Output is correct
9 Correct 7 ms 1616 KB Output is correct
10 Correct 32 ms 5152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 12 ms 2504 KB Output is correct
7 Correct 7 ms 672 KB Output is correct
8 Correct 22 ms 4676 KB Output is correct
9 Correct 7 ms 1616 KB Output is correct
10 Correct 33 ms 5320 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 12 ms 2084 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 34 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 920 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 11 ms 1336 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 16 ms 2268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 38 ms 4156 KB Output is correct
10 Correct 25 ms 3536 KB Output is correct
11 Correct 9 ms 1600 KB Output is correct
12 Correct 11 ms 1808 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 31 ms 4164 KB Output is correct
10 Correct 25 ms 3564 KB Output is correct
11 Correct 9 ms 1492 KB Output is correct
12 Correct 11 ms 1876 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 38 ms 5268 KB Output is correct
15 Correct 45 ms 6012 KB Output is correct
16 Correct 7 ms 1292 KB Output is correct
17 Correct 28 ms 4044 KB Output is correct
18 Correct 18 ms 2372 KB Output is correct