답안 #107721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107721 2019-04-25T14:27:23 Z FiloSanza 곤돌라 (IOI14_gondola) C++14
25 / 100
71 ms 5468 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;

int valid(int N, int inputSeq[])
{
    vector<int> v, s;
    v.reserve(N);
    for(int i=0; i<N; i++) 
        if(inputSeq[i] <= N)
            v.push_back(inputSeq[i]);
        else
            s.push_back(inputSeq[i]);

    sort(s.begin(), s.end());
    for(int i=1; i<s.size(); i++) if(s[i-1] == s[i]) return 0;
    if(!s.empty() && s.back() > N + s.size()) return 0;

    int mini = min_element(v.begin(), v.end()) - v.begin();

    map<int, int> cont;
    for(auto i : v) cont[i]++;

    for(auto i : cont) if(i.second > 1) return 0;

    for(int i=mini+1; i!=mini; i=(i+1)%v.size()){
        if(i == 0 && v.back() >= v.front()) return 0;
        if(v[i] <= v[i-1]) return 0;
    }

    return 1;
}

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

int replacement(int N, int gondolaSeq[], int replacementSeq[])
{
    int cont = 0;
    vector<int> seq;
    vector<int> v, s;
    for(int i=0; i<N; i++) 
        if(gondolaSeq[i] <= N)
            v.push_back(gondolaSeq[i]);
        else
            s.push_back(gondolaSeq[i]);

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

    if(s.empty()) return 0;

    if(!v.empty()){
        deque<int> q;
        for(int i=0; i<N; i++) q.push_back(gondolaSeq[i]);

        while(q.front() != v.front()){
            q.push_front(q.back());
            q.pop_back();
        }

        for(int i=1; i<v.front(); i++){
            q.push_front(q.back());
            q.pop_back();
        }
        
        while(!q.empty()){
            seq.push_back(q.front());
            q.pop_front();
        }
    }
    else{
        seq = s;
    }
    
    vector<pair<int, int>> todo;

    for(int i=0; i<N; i++){
        if(seq[i] == 1+i+N)
            replacementSeq[cont++] = i+1;
        else if(seq[i] > N){
            todo.push_back({seq[i], i+1});
        }
    }

    if(todo.empty()) return cont;
    sort(todo.begin(), todo.end());

    int next_val = N+cont+1;
    for(auto i : todo){
        int to = i.second;
        while(next_val <= i.first){
            replacementSeq[cont++] = to;
            to = next_val;
            next_val++;
        }
    }

    return cont;
}

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

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

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:17:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<s.size(); i++) if(s[i-1] == s[i]) return 0;
                  ~^~~~~~~~~
gondola.cpp:18:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(!s.empty() && s.back() > N + s.size()) return 0;
                      ~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 356 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 14 ms 2560 KB Output is correct
7 Correct 42 ms 4572 KB Output is correct
8 Correct 27 ms 4600 KB Output is correct
9 Correct 11 ms 1664 KB Output is correct
10 Correct 45 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 356 KB Output is correct
6 Correct 71 ms 2552 KB Output is correct
7 Correct 38 ms 4600 KB Output is correct
8 Correct 30 ms 4660 KB Output is correct
9 Correct 11 ms 1636 KB Output is correct
10 Correct 35 ms 5196 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 14 ms 1024 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 17 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 412 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 304 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 356 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 Incorrect 2 ms 384 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 256 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 384 KB Output is correct
6 Incorrect 3 ms 256 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 336 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Integer -3 violates the range [0, 1000000008]
2 Halted 0 ms 0 KB -