답안 #281671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281671 2020-08-23T09:50:42 Z SamAnd 곤돌라 (IOI14_gondola) C++17
90 / 100
1000 ms 5752 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005, M = 1000000009;

int n;
int a[N];

int valid(int n, int inputSeq[])
{
    ::n = n;
    for (int i = 0; i < n; ++i)
        a[i] = inputSeq[i];

    set<int> s;
    for (int i = 0; i < n; ++i)
        s.insert(a[i]);
    if (sz(s) != n)
        return 0;

    int minu = M;
    int mini;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] < minu)
        {
            minu = a[i];
            mini = i;
        }
    }

    int q = 0;
    for (int i = mini; i < n; ++i)
    {
        if (a[i] <= n)
        {
            if (a[i] != minu + q)
                return 0;
        }
        ++q;
    }
    for (int i = 0; i < mini; ++i)
    {
        if (a[i] <= n)
        {
            if (a[i] != minu + q)
                return 0;
        }
        ++q;
    }

    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    ::n = n;
    for (int i = 0; i < n; ++i)
        a[i] = gondolaSeq[i];

    int m = 0;

    vector<pair<int, int> > v;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] > n)
        {
            v.push_back(m_p(a[i], i));
        }
    }

    sort(all(v));
    reverse(all(v));

    ///////////////////////////////////////////
    int minu = M;
    int mini;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] < minu)
        {
            minu = a[i];
            mini = i;
        }
    }

    if (minu > n)
    {
        minu = 1;
    }

    for (int i = mini; i < n; ++i)
    {
        if (minu > n)
            minu = 1;
        a[i] = minu;
        ++minu;
    }
    for (int i = 0; i < mini; ++i)
    {
        if (minu > n)
            minu = 1;
        a[i] = minu;
        ++minu;
    }
    ///////////////////////////////////////////

    int u = n + 1;
    while (!v.empty())
    {
        if (u == v.back().fi)
        {
            replacementSeq[m++] = a[v.back().se];
            a[v.back().se] = u;
            v.pop_back();
        }
        else
        {
            replacementSeq[m++] = a[v.back().se];
            a[v.back().se] = u;
        }
        ++u;
    }

    return m;
}

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

int countReplacement(int n, int inputSeq[])
{
    if (valid(n, inputSeq) == 0)
        return 0;

    ::n = n;
    for (int i = 0; i < n; ++i)
        a[i] = inputSeq[i];

    vector<pair<int, int> > v;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] > n)
        {
            v.push_back(m_p(a[i], i));
        }
    }

    sort(all(v));
    reverse(all(v));

    bool z = (sz(v) == n);

    int ans = 1;

    int u = n + 1;
    while (!v.empty())
    {
        if (u == v.back().fi)
        {
            v.pop_back();
        }
        else
        {
            ans = (ans * 1LL * sz(v)) % M;
        }
        ++u;
    }

    if (z)
        ans = (ans * 1LL * n) % M;

    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:28:9: warning: 'mini' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |     int mini;
      |         ^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:85:9: warning: 'mini' may be used uninitialized in this function [-Wmaybe-uninitialized]
   85 |     int mini;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 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 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 13 ms 2560 KB Output is correct
7 Correct 37 ms 4472 KB Output is correct
8 Correct 27 ms 4600 KB Output is correct
9 Correct 8 ms 1664 KB Output is correct
10 Correct 30 ms 5368 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 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 13 ms 2560 KB Output is correct
7 Correct 33 ms 4472 KB Output is correct
8 Correct 26 ms 4608 KB Output is correct
9 Correct 10 ms 1664 KB Output is correct
10 Correct 34 ms 5368 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 21 ms 2432 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 44 ms 5496 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 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 0 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 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 4 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 21 ms 1408 KB Output is correct
12 Correct 14 ms 1536 KB Output is correct
13 Correct 18 ms 1680 KB Output is correct
14 Correct 12 ms 1408 KB Output is correct
15 Correct 25 ms 2416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 45 ms 4864 KB Output is correct
10 Correct 43 ms 4020 KB Output is correct
11 Correct 14 ms 1664 KB Output is correct
12 Correct 16 ms 2048 KB Output is correct
13 Correct 5 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 1 ms 384 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 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 43 ms 4856 KB Output is correct
10 Correct 34 ms 4088 KB Output is correct
11 Correct 14 ms 1664 KB Output is correct
12 Correct 19 ms 2048 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Execution timed out 1067 ms 5752 KB Time limit exceeded
15 Halted 0 ms 0 KB -