답안 #792166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792166 2023-07-24T16:46:08 Z caganyanmaz 곤돌라 (IOI14_gondola) C++17
100 / 100
44 ms 5944 KB
#include "gondola.h"
#define pb push_back
#define mp(x...) array<int,2>({x})
#include <bits/stdc++.h>
using namespace std;

int n;
int *v;


int fix(int i)
{
        int res = i % n;
        if (res < 0)
                res += n;
        return res;
}

int right(int i)
{
        return fix(i+1);
}

bool unique()
{
        set<int> numbers;
        for (int i = 0; i < n; i++)
        {
                if (numbers.find(v[i]) != numbers.end())
                        return 0;
                numbers.insert(v[i]);
        }
        return 1;
}

int find_mi()
{
        int mi = 0;
        for (int i = 1; i < n; i++)
                if (v[i] < v[mi])
                        mi = i;
        return mi;
}

int valid(int nn, int vv[])
{
        v = vv;
        n = nn;
        if (!unique())
                return 0;
        int mi = find_mi();
        if (v[mi] > n)
                return 1;
        int si = fix(mi - v[mi] + 1);
        if (v[si] != 1 && v[si] <= n)
                return 0;
        for (int j = right(si), i = 1; j != si; j=right(j))
                if (v[j] != ++i && v[j] <= n)
                        return 0;
        return 1;
}

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


int replacement(int nn, int vv[], int rr[])
{
        n = nn;
        v = vv;
        int mi = find_mi();
        vector<array<int, 2>> p;
        int si = fix(mi - v[mi] + 1);
        if (v[si] > n)
                p.pb(mp(v[si], 1));
        for (int j = right(si), i = 2; j != si; j=right(j), i++)
                if (v[j] > n)
                        p.pb(mp(v[j], i));
        sort(p.begin(), p.end());
        int li = n;
        for (auto [val, i] : p)
        {
                rr[(li++)-n] = i;
                while (li != val) {rr[li-n] = li; li++;}
        }
        return li - n;


}

constexpr static int MOD = 1e9 + 9; // Kys :)
//----------------------

int mul(int64_t a, int64_t b)
{
        int res = (a*b) % MOD;
        if (res < 0)
                res += MOD;
        return res;
}


int pow(int a, int b)
{
        int res = 1;
        while (b)
        {
                if (b&1)
                {
                        b--;
                        res = mul(res, a);
                }
                else
                {
                        b >>= 1;
                        a = mul(a, a);
                }
        }
        return res;
}

int countReplacement(int nn, int vv[])
{
        n = nn;
        v = vv;
        int res = 1;
        int mi = find_mi();
        if (v[mi] > n)
                res = n;
        vector<int> vals;
        if (!valid(n, v))
                return 0;
        for (int i = 0; i < n; i++)
                if (v[i] > n)
                        vals.pb(v[i]);
        sort(vals.begin(), vals.end());
        int vs = vals.size();
        int last = n;
        for (int i : vals)
        {
                res = mul(res, pow(vs, i - last - 1));
                last = i;
                vs--;
        }
        return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 2384 KB Output is correct
7 Correct 7 ms 1084 KB Output is correct
8 Correct 20 ms 4244 KB Output is correct
9 Correct 7 ms 1472 KB Output is correct
10 Correct 26 ms 5048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 11 ms 2388 KB Output is correct
7 Correct 10 ms 1120 KB Output is correct
8 Correct 19 ms 4288 KB Output is correct
9 Correct 6 ms 1528 KB Output is correct
10 Correct 25 ms 4952 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 12 ms 2288 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 32 ms 5176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 312 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 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 7 ms 1060 KB Output is correct
12 Correct 8 ms 1124 KB Output is correct
13 Correct 12 ms 1364 KB Output is correct
14 Correct 7 ms 956 KB Output is correct
15 Correct 16 ms 2264 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 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 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 30 ms 4436 KB Output is correct
10 Correct 35 ms 3788 KB Output is correct
11 Correct 9 ms 1492 KB Output is correct
12 Correct 11 ms 1832 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 264 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 37 ms 4472 KB Output is correct
10 Correct 25 ms 3768 KB Output is correct
11 Correct 12 ms 1492 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 38 ms 5292 KB Output is correct
15 Correct 44 ms 5944 KB Output is correct
16 Correct 10 ms 1260 KB Output is correct
17 Correct 35 ms 4032 KB Output is correct
18 Correct 16 ms 2448 KB Output is correct