답안 #62592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62592 2018-07-29T09:11:38 Z evpipis 곤돌라 (IOI14_gondola) C++11
100 / 100
35 ms 8568 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

//#define TEST

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

const int mod = 1e9+9;

#ifdef TEST
int gondolaSequence[100001];
int replacementSequence[250001];
#endif

int add(int a, int b){
    return (a+b)%mod;
}

int mul(int a, int b){
    return (a*1LL*b)%mod;
}

int po(int a, int b){
    if (b == 0) return 1;
    if (b%2 == 0) return po(mul(a, a), b/2);
    return mul(a, po(mul(a, a), b/2));
}

int valid(int n, int arr[]){
    int pos = -1;
    for (int i = 0; i < n; i++)
        if (arr[i] <= n) pos = i;

    if (pos != -1){
        int cur = arr[pos];
        for (int i = 0; i < n; i++){
            if (arr[pos] <= n && arr[pos] != cur)
                return 0;

            cur = cur%n+1;
            pos = (pos+1)%n;
        }
    }

    sort(arr, arr+n);
    for (int i = 0; i < n-1; i++)
        if (arr[i] == arr[i+1])
            return 0;
    return 1;
}

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

int replacement(int n, int arr[], int out[]){
    vector<ii> vec;
    int pos = -1, nex = n+1, m = 0, cur;
    for (int i = 0; i < n; i++)
        if (arr[i] <= n) pos = i;

    if (pos == -1)
        pos = 0, cur = 1;
    else
        cur = arr[pos];

    for (int i = 0; i < n; i++){
        if (arr[pos] > n)
            vec.pb(mp(arr[pos], cur));

        pos = (pos+1)%n;
        cur = cur%n+1;
    }

    sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); i++)
        while (vec[i].fi > vec[i].se)
            out[m++] = vec[i].se, vec[i].se = nex++;

    return m;
}

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

int countReplacement(int n, int arr[]){
    vector<int> vec;
    if (!valid(n, arr))
        return 0;

    vec.pb(n);
    for (int i = 0; i < n; i++)
        if (arr[i] > n) vec.pb(arr[i]);

    int ans = 1;
    sort(vec.begin(), vec.end());
    for (int i = 1; i < vec.size(); i++)
        ans = mul(ans, po(vec.size()-i, vec[i]-vec[i-1]-1));

    if (vec.size() == n+1)
        ans = mul(ans, n);
    return ans;
}

#ifdef TEST
int main()
{
  int i, n, tag;
  int nr;
  assert(scanf("%d", &tag)==1);
  assert(scanf("%d", &n)==1);
  for(i=0;i< n;i++)
    assert( scanf("%d", &gondolaSequence[i]) ==1);

  switch (tag){
  case 1: case 2: case 3:
    printf("%d\n", valid(n, gondolaSequence));
    break;

  case 4: case 5: case 6:
    nr = replacement(n, gondolaSequence, replacementSequence);
    printf("%d\n", nr);
    if (nr > 0)
      {
	for (i=0; i<nr-1; i++)
	  printf("%d ", replacementSequence[i]);
	printf("%d\n", replacementSequence[nr-1]);
      }
    else printf("\n");
    break;

  case 7: case 8: case 9: case 10:
    printf("%d\n",  countReplacement(n, gondolaSequence));
    break;
  }

  return 0;
}
#endif
/*
3 5
10 4 3 11 12

3 7
2 3 4 9 6 7 1

6 7
2 3 4 9 6 7 1

10 2
3 4
*/

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:80:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:100:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < vec.size(); i++)
                     ~~^~~~~~~~~~~~
gondola.cpp:103:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (vec.size() == n+1)
         ~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Correct 3 ms 412 KB Output is correct
4 Correct 3 ms 420 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 488 KB Output is correct
2 Correct 2 ms 540 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 3 ms 548 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 11 ms 864 KB Output is correct
7 Correct 18 ms 1588 KB Output is correct
8 Correct 20 ms 1708 KB Output is correct
9 Correct 10 ms 1708 KB Output is correct
10 Correct 33 ms 2148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2148 KB Output is correct
2 Correct 3 ms 2148 KB Output is correct
3 Correct 3 ms 2148 KB Output is correct
4 Correct 3 ms 2148 KB Output is correct
5 Correct 3 ms 2148 KB Output is correct
6 Correct 12 ms 2200 KB Output is correct
7 Correct 23 ms 2820 KB Output is correct
8 Correct 15 ms 2820 KB Output is correct
9 Correct 10 ms 2820 KB Output is correct
10 Correct 24 ms 2820 KB Output is correct
11 Correct 3 ms 2820 KB Output is correct
12 Correct 2 ms 2820 KB Output is correct
13 Correct 8 ms 2820 KB Output is correct
14 Correct 2 ms 2820 KB Output is correct
15 Correct 16 ms 2820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2820 KB Output is correct
2 Correct 3 ms 2820 KB Output is correct
3 Correct 3 ms 2820 KB Output is correct
4 Correct 3 ms 2820 KB Output is correct
5 Correct 2 ms 2820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2820 KB Output is correct
2 Correct 3 ms 2820 KB Output is correct
3 Correct 3 ms 2820 KB Output is correct
4 Correct 2 ms 2820 KB Output is correct
5 Correct 3 ms 2820 KB Output is correct
6 Correct 3 ms 2820 KB Output is correct
7 Correct 3 ms 2820 KB Output is correct
8 Correct 4 ms 2820 KB Output is correct
9 Correct 4 ms 2820 KB Output is correct
10 Correct 4 ms 2820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2820 KB Output is correct
2 Correct 2 ms 2820 KB Output is correct
3 Correct 3 ms 2820 KB Output is correct
4 Correct 3 ms 2820 KB Output is correct
5 Correct 2 ms 2820 KB Output is correct
6 Correct 3 ms 2820 KB Output is correct
7 Correct 3 ms 2820 KB Output is correct
8 Correct 3 ms 2820 KB Output is correct
9 Correct 4 ms 2820 KB Output is correct
10 Correct 3 ms 2820 KB Output is correct
11 Correct 13 ms 2820 KB Output is correct
12 Correct 17 ms 2820 KB Output is correct
13 Correct 19 ms 3448 KB Output is correct
14 Correct 14 ms 3448 KB Output is correct
15 Correct 30 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4452 KB Output is correct
2 Correct 3 ms 4452 KB Output is correct
3 Correct 3 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4452 KB Output is correct
2 Correct 2 ms 4452 KB Output is correct
3 Correct 3 ms 4452 KB Output is correct
4 Correct 3 ms 4452 KB Output is correct
5 Correct 3 ms 4452 KB Output is correct
6 Correct 3 ms 4452 KB Output is correct
7 Correct 3 ms 4452 KB Output is correct
8 Correct 2 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4452 KB Output is correct
2 Correct 3 ms 4452 KB Output is correct
3 Correct 2 ms 4452 KB Output is correct
4 Correct 3 ms 4452 KB Output is correct
5 Correct 4 ms 4452 KB Output is correct
6 Correct 3 ms 4452 KB Output is correct
7 Correct 3 ms 4452 KB Output is correct
8 Correct 2 ms 4452 KB Output is correct
9 Correct 32 ms 4452 KB Output is correct
10 Correct 22 ms 4452 KB Output is correct
11 Correct 12 ms 4452 KB Output is correct
12 Correct 13 ms 4452 KB Output is correct
13 Correct 4 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4452 KB Output is correct
2 Correct 3 ms 4452 KB Output is correct
3 Correct 3 ms 4452 KB Output is correct
4 Correct 3 ms 4452 KB Output is correct
5 Correct 4 ms 4452 KB Output is correct
6 Correct 3 ms 4452 KB Output is correct
7 Correct 2 ms 4452 KB Output is correct
8 Correct 2 ms 4452 KB Output is correct
9 Correct 25 ms 5168 KB Output is correct
10 Correct 23 ms 5496 KB Output is correct
11 Correct 10 ms 5496 KB Output is correct
12 Correct 13 ms 5548 KB Output is correct
13 Correct 4 ms 5548 KB Output is correct
14 Correct 35 ms 7048 KB Output is correct
15 Correct 34 ms 7996 KB Output is correct
16 Correct 9 ms 7996 KB Output is correct
17 Correct 31 ms 8360 KB Output is correct
18 Correct 15 ms 8568 KB Output is correct