답안 #98754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98754 2019-02-25T15:40:21 Z Alexa2001 곤돌라 (IOI14_gondola) C++17
75 / 100
76 ms 3320 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 250005, Mod = 1e9 + 9;
typedef long long ll;

int a[Nmax];

int valid(int n, int A[])
{
    map<int,int> ap;

    int i, rot = Mod;
    for(i=0; i<n; ++i)
        if(A[i] <= n)
        {
            if(rot == Mod) rot = (n + i - A[i]) % n;
                else if(rot != (n + i - A[i]) % n) return 0;
        }
        else ++ap[A[i]];

    for(auto it : ap)
        if(it.second > 1) return 0;
    return 1;
}

bool cmp(int x, int y)
{
    return a[x] < a[y];
}

int replacement(int n, int A[], int ans[])
{
    int i, last = n+1, rot = 0;
    vector<int> v;

    for(i=0; i<n; ++i)
        if(A[i] <= n) rot = (A[i] - 1) - i;
    if(rot < 0) rot += n;

    for(i=0; i<n; ++i) a[(i + rot) % n] = A[i];

    for(i=0; i<n; ++i)
        if(a[i] > n) v.push_back(i);

    sort(v.begin(), v.end(), cmp);

    int nr = 0;
    for(auto it : v)
    {
        ans[nr++] = it+1;
        for(i=last; i<a[it]; ++i) ans[nr++] = i;
        last = a[it] + 1;
    }
    return nr;
}

ll power(ll a, int b)
{
    ll ans = 1;
    while(b)
    {
        if(b&1) ans = ans * a % Mod;
        a = a * a % Mod; b >>= 1;
    }
    return ans;
}

int countReplacement(int n, int A[])
{
    if(!valid(n, A)) return 0;

    int i;
    vector<int> v;
    for(i=0; i<n; ++i)
        if(A[i] > n) v.push_back(A[i] - n);

    sort(v.begin(), v.end());
    int m = v.size();
    ll ans = 1;

    int last = 0;
    for(auto it : v)
    {
        ans *= power(m, it - last - 1);
        ans %= Mod;
        --m;
        last = it;
    }
    return (int) ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 9 ms 512 KB Output is correct
7 Correct 20 ms 716 KB Output is correct
8 Correct 15 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 15 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 512 KB Output is correct
7 Correct 18 ms 640 KB Output is correct
8 Correct 10 ms 640 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 16 ms 640 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 10 ms 632 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 22 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 356 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1536 KB Output is correct
12 Correct 13 ms 1536 KB Output is correct
13 Correct 25 ms 1672 KB Output is correct
14 Correct 13 ms 1408 KB Output is correct
15 Correct 24 ms 2416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 59 ms 3320 KB Output is correct
10 Correct 35 ms 2608 KB Output is correct
11 Correct 17 ms 1536 KB Output is correct
12 Correct 19 ms 1664 KB Output is correct
13 Incorrect 8 ms 768 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 76 ms 3320 KB Output is correct
10 Correct 38 ms 2688 KB Output is correct
11 Correct 19 ms 1408 KB Output is correct
12 Correct 22 ms 1664 KB Output is correct
13 Incorrect 6 ms 640 KB Output isn't correct
14 Halted 0 ms 0 KB -