답안 #148131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148131 2019-08-31T14:08:39 Z WhipppedCream 곤돌라 (IOI14_gondola) C++17
100 / 100
39 ms 3152 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
#ifdef atom
    #include "grader.cpp"
#else
    #include "gondola.h"
#endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
int valid(int n, int arr[])
{
    for(int i = 0; i< n; i++) arr[i]--;
    vi vec;
    for(int i = 0; i< n; i++) vec.pb(arr[i]);
    sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end())-vec.begin());
    if(vec.size() != n) return 0;
    vi tmp;
    for(int i = 0; i< n; i++) if(arr[i]< n) tmp.pb((arr[i]-i+n)%n);
    sort(tmp.begin(), tmp.end()); tmp.resize(unique(tmp.begin(), tmp.end())-tmp.begin());
    return (tmp.size()<= 1);
}
int replacement(int n, int arr[], int ans[])
{
    for(int i = 0; i< n; i++) arr[i]--;
    vi tmp;
    for(int i = 0; i< n; i++) if(arr[i]< n) tmp.pb((arr[i]-i+n)%n);
    sort(tmp.begin(), tmp.end()); tmp.resize(unique(tmp.begin(), tmp.end())-tmp.begin());
    int q = tmp.size();
    int st = q?tmp[0]:0;
    vii strange;
    for(int i = 0; i< n; i++) if(arr[i]>= n) strange.pb(ii(arr[i], (i+st)%n));
    sort(strange.begin(), strange.end());
    int ptr = 0;
    for(int i = 0; i< strange.size(); i++)
    {
        //printf("%d %d\n", strange[i].X, strange[i].Y);
        int prv = i?strange[i-1].X:n-1;
        int rounds = strange[i].X-prv;
        rounds--;
        ans[ptr++] = strange[i].Y+1;
        while(rounds--)
        {
            ans[ptr] = n+ptr;
            ptr++;
        }
    }
    return ptr;
}

//----------------------
const int md = 1e9+9;
int mul(int a, int b)
{
    return (1LL*a*b)%md;
}
int ninja(int a, int b)
{
    if(b == 0) return 1;
    int x = ninja(a, b/2);
    int y = mul(x, x);
    if(b%2) y = mul(y, a);
    return y;
}
int countReplacement(int n, int arr[])
{
    if(!valid(n, arr)) return 0;
    vi tmp;
    for(int i = 0; i< n; i++) if(arr[i]< n) tmp.pb((arr[i]-i+n)%n);
    sort(tmp.begin(), tmp.end()); tmp.resize(unique(tmp.begin(), tmp.end())-tmp.begin());
    int q = tmp.size();
    int st = q?tmp[0]:0;
    vii strange;
    for(int i = 0; i< n; i++) if(arr[i]>= n) strange.pb(ii(arr[i], (i+st)%n));
    sort(strange.begin(), strange.end());
    int ptr = 0;
    int res = 1;
    for(int i = 0; i< strange.size(); i++)
    {
        //printf("%d %d\n", strange[i].X, strange[i].Y);
        int prv = i?strange[i-1].X:n-1;
        int rounds = strange[i].X-prv;
        rounds--;
        //printf("pow %d %d\n", strange.size()-i, rounds);
        res = mul(res, ninja(strange.size()-i, rounds));
    }
    if(!q) res = mul(res, strange.size());
    return res;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(vec.size() != n) return 0;
        ~~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:39:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i< strange.size(); i++)
                    ~^~~~~~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:82:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i< strange.size(); i++)
                    ~^~~~~~~~~~~~~~~~
gondola.cpp:80:9: warning: unused variable 'ptr' [-Wunused-variable]
     int ptr = 0;
         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 11 ms 1268 KB Output is correct
7 Correct 21 ms 1776 KB Output is correct
8 Correct 16 ms 2032 KB Output is correct
9 Correct 8 ms 888 KB Output is correct
10 Correct 22 ms 2160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 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 376 KB Output is correct
6 Correct 11 ms 1268 KB Output is correct
7 Correct 21 ms 1780 KB Output is correct
8 Correct 16 ms 2032 KB Output is correct
9 Correct 8 ms 888 KB Output is correct
10 Correct 22 ms 2288 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 11 ms 1144 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 27 ms 2032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 396 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 400 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 14 ms 1780 KB Output is correct
12 Correct 16 ms 1836 KB Output is correct
13 Correct 18 ms 1532 KB Output is correct
14 Correct 14 ms 1780 KB Output is correct
15 Correct 23 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 272 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 27 ms 2116 KB Output is correct
10 Correct 22 ms 1836 KB Output is correct
11 Correct 10 ms 920 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 29 ms 2116 KB Output is correct
10 Correct 24 ms 1964 KB Output is correct
11 Correct 10 ms 916 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 35 ms 2968 KB Output is correct
15 Correct 39 ms 3152 KB Output is correct
16 Correct 9 ms 932 KB Output is correct
17 Correct 26 ms 2028 KB Output is correct
18 Correct 16 ms 1624 KB Output is correct