답안 #891549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891549 2023-12-23T08:20:52 Z AkibAzmain 곤돌라 (IOI14_gondola) C++17
100 / 100
16 ms 3024 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
using ll = long long;

int valid(int n, int a[])
{
  bool y = true;
  for (int i = 1; y && i < n; ++i) y = (a[i] - a[i - 1] + n) % n == 1;
  return y;
}

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

int replacement(int n, int a[], int ans[])
{
  int org = -1;
  for (int i = 0; i < n; ++i)
    if (a[i] <= n)
      {
        int norg = (i - a[i] + 1 + n) % n;
        assert (org == -1 || org == norg);
        org = norg;
      }
  if (org == -1) org = 0;
  vector < pair < int, int > > v;
  for (int i = 0; i < n; ++i) if (a[i] > n) v.push_back ({ a[i], (i - org + n) % n + 1 });
  sort (v.begin (), v.end ());
  int i = 0;
  for (auto &x : v)
    {
      while (x.first != x.second)
        {
          ans[i] = x.second;
          x.second = i + n + 1;
          ++i;
        }
    }
  return i;
}

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

ll MOD = 1000000009;

ll
binpow (ll a, ll b)
{
  ll ans = 1;
  while (b)
    {
      if (b % 2) (ans *= a) %= MOD;
      b /= 2;
      if (b) (a *= a) %= MOD;
    }
  return ans;
}

int countReplacement(int n, int a[])
{
  int org = -1;
  for (int i = 0; i < n; ++i)
    if (a[i] <= n)
      {
        int norg = (i - a[i] + 1 + n) % n;
        if (org != -1 && org != norg) return 0;
        org = norg;
      }
  bool ind = false;
  if (org == -1) org = 0, ind = true;
  vector < ll > v;
  for (int i = 0; i < n; ++i) if (a[i] > n) v.push_back (a[i]);
  sort (v.begin (), v.end ());
  ll vs = v.size (), ans = 1, p = n;
  for (auto &x : v)
    (ans *= binpow (vs--, x - p - 1)) %= MOD, p = x;
  if (ind) (ans *= (ll) n) %= MOD;
  return ans;
}
# 결과 실행 시간 메모리 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 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 7 ms 604 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 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 6 ms 604 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 0 ms 356 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 11 ms 740 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
# 결과 실행 시간 메모리 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 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
# 결과 실행 시간 메모리 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 6 ms 600 KB Output is correct
12 Correct 7 ms 604 KB Output is correct
13 Correct 11 ms 1256 KB Output is correct
14 Correct 6 ms 604 KB Output is correct
15 Correct 16 ms 2388 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 508 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 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 612 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 11 ms 1324 KB Output is correct
10 Correct 8 ms 1236 KB Output is correct
11 Correct 4 ms 856 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 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 1 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 10 ms 1236 KB Output is correct
10 Correct 9 ms 1240 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 4 ms 860 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 14 ms 1748 KB Output is correct
15 Correct 16 ms 3024 KB Output is correct
16 Correct 4 ms 864 KB Output is correct
17 Correct 11 ms 1928 KB Output is correct
18 Correct 6 ms 1496 KB Output is correct