답안 #107780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107780 2019-04-25T19:08:28 Z FiloSanza 곤돌라 (IOI14_gondola) C++14
45 / 100
46 ms 4864 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;

    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<pair<int, int>> s;
    vector<int> v;

    for(int i=0; i<N; i++) 
        if(gondolaSeq[i] <= N)
            v.push_back(gondolaSeq[i]);

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

    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{
        for(int i=0; i<N; i++) seq.push_back(gondolaSeq[i]);
    }
    
    for(int i=0; i<N; i++){
        if(seq[i] >= N)
            s.push_back({seq[i], i+1});
    }

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

    if(s.empty()) return 0;

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

    return cont;
}

//----------------------
const int MOD = 1e9+9;

int countReplacement(int N, int gondolaSeq[])
{
    if(valid(N, gondolaSeq) == 0) return 0;

    int cont = 0;
    vector<int> seq;
    vector<int> s;
    vector<int> v;

    for(int i=0; i<N; i++) 
        if(gondolaSeq[i] <= N)
            v.push_back(gondolaSeq[i]);

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

    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{
        for(int i=0; i<N; i++) seq.push_back(gondolaSeq[i]);
    }    
    for(int i=0; i<N; i++){
        if(seq[i] >= N)
            s.push_back(seq[i]);
    }

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

    if(s.empty()) return 0;
    int curr = N+1, pos = 0;
    int ans = 1;
    while(curr < s.back()){
        if(curr == s[pos]){
            curr++;
            pos++;
            continue;
        }

        ans = (ans * (s.size() - pos)) % MOD;
        curr++;
    }    
    if(s.size() == N) ans = (ans * N) % MOD;
    return ans;
}

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: In function 'int countReplacement(int, int*)':
gondola.cpp:154:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(s.size() == N) ans = (ans * N) % MOD;
        ~~~~~~~~~^~~~
gondola.cpp:101:9: warning: unused variable 'cont' [-Wunused-variable]
     int cont = 0;
         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 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 16 ms 2432 KB Output is correct
7 Correct 46 ms 3964 KB Output is correct
8 Correct 30 ms 4188 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 34 ms 4864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 14 ms 2432 KB Output is correct
7 Correct 42 ms 4072 KB Output is correct
8 Correct 25 ms 4224 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 32 ms 4856 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Incorrect 2 ms 384 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 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 4 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 15 ms 2040 KB Output is correct
12 Correct 18 ms 2168 KB Output is correct
13 Correct 17 ms 1400 KB Output is correct
14 Correct 15 ms 2032 KB Output is correct
15 Correct 22 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -