답안 #70096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70096 2018-08-22T10:37:45 Z zubec 곤돌라 (IOI14_gondola) C++14
55 / 100
27 ms 4472 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 100100;

int a[N], b[N];

int valid(int n, int inputSeq[]){

    map<int, int> mp1;
    map<int, int> used, used2;
    for (int i = 1; i <= n; i++){
        a[i] = inputSeq[i-1];
        if (a[i] > n){
            if (++mp1[a[i]] > 1)
                return 0;
        }
    }
    a[n+1] = a[1];
    int prev = 0;
    for (int i = 1; i <= n; i++){
        if (used.find(a[i+1]) != used.end())
            a[i+1] = used[a[i+1]];
        if (a[i] > n)
            continue;
        if (a[i+1] > n){
            if (a[i] == n){
                if (used2.find(1) != used2.end())
                    return 0;
                used[a[i+1]] = 1;
                used2[1] = a[i+1];
                a[i+1] = 1;
            } else {
                if (used2.find(a[i]+1) != used2.end())
                    return 0;
                used[a[i+1]] = a[i]+1;
                used2[a[i]+1] = a[i+1];
                a[i+1] = a[i]+1;
            }
        } else {
            if (a[i] == n){
                if (a[i+1] != 1)
                    return 0;
            } else {
                if (a[i+1] != a[i] + 1)
                    return 0;
            }
        }
    }

    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    vector <pair<int, int> > vec;
    for (int i = 1; i <= n; i++){
        a[i] = gondolaSeq[i-1];
        if (a[i] > n){
            vec.push_back({a[i], i});
        }
    }
    a[n+1] = a[1];

    for (int i = 1; i <= n; i++){
        if (a[i] <= n){
            if (a[i] == n)
                a[i+1] = 1; else
                a[i+1] = a[i] + 1;
        }
    }
    for (int i = n+1; i > 1; i--){
        if (a[i] <= n){
            if (a[i] == 1)
                a[i-1] = n; else
                a[i-1] = a[i] - 1;
        }
    }
    if (a[1] > n){
        for (int i = 1; i <= n; i++)
            a[i] = i;
    }

    int cnt = 0;
    int curnumb = n+1;
    sort(vec.begin(), vec.end());
    for (int i = 0; i < vec.size(); i++){
        int cur = a[vec[i].second];
        while(cur != vec[i].first){
            replacementSeq[cnt++] = cur;
            cur = curnumb;
            ++curnumb;
        }
    }
    return cnt;


}

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

int countReplacement(int n, int inputSeq[]){
  return -3;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:21:9: warning: unused variable 'prev' [-Wunused-variable]
     int prev = 0;
         ^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:89:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 8 ms 872 KB Output is correct
7 Correct 17 ms 1256 KB Output is correct
8 Correct 12 ms 1256 KB Output is correct
9 Correct 6 ms 1256 KB Output is correct
10 Correct 21 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Correct 3 ms 1260 KB Output is correct
4 Correct 3 ms 1260 KB Output is correct
5 Correct 4 ms 1260 KB Output is correct
6 Correct 11 ms 1260 KB Output is correct
7 Correct 26 ms 1400 KB Output is correct
8 Correct 16 ms 1400 KB Output is correct
9 Correct 10 ms 1400 KB Output is correct
10 Correct 19 ms 1400 KB Output is correct
11 Correct 2 ms 1400 KB Output is correct
12 Correct 2 ms 1400 KB Output is correct
13 Correct 23 ms 2412 KB Output is correct
14 Correct 2 ms 2412 KB Output is correct
15 Correct 27 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2412 KB Output is correct
2 Correct 2 ms 2412 KB Output is correct
3 Correct 2 ms 2412 KB Output is correct
4 Correct 2 ms 2412 KB Output is correct
5 Correct 2 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2412 KB Output is correct
2 Correct 3 ms 2412 KB Output is correct
3 Correct 3 ms 2412 KB Output is correct
4 Correct 2 ms 2412 KB Output is correct
5 Correct 3 ms 2412 KB Output is correct
6 Correct 3 ms 2412 KB Output is correct
7 Correct 3 ms 2412 KB Output is correct
8 Correct 2 ms 2412 KB Output is correct
9 Correct 3 ms 2412 KB Output is correct
10 Correct 3 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2412 KB Output is correct
2 Correct 2 ms 2412 KB Output is correct
3 Correct 2 ms 2412 KB Output is correct
4 Correct 2 ms 2412 KB Output is correct
5 Correct 2 ms 2412 KB Output is correct
6 Correct 2 ms 2412 KB Output is correct
7 Correct 2 ms 2412 KB Output is correct
8 Correct 4 ms 2412 KB Output is correct
9 Correct 3 ms 2412 KB Output is correct
10 Correct 3 ms 2412 KB Output is correct
11 Correct 16 ms 2412 KB Output is correct
12 Correct 15 ms 2412 KB Output is correct
13 Correct 20 ms 2948 KB Output is correct
14 Correct 16 ms 2948 KB Output is correct
15 Correct 26 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4472 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4472 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4472 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4472 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -