제출 #288316

#제출 시각아이디문제언어결과실행 시간메모리
288316Atill83Gondola (IOI14_gondola)C++14
25 / 100
15 ms1280 KiB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e5 + 5;
int yer[MAXN];
int valid(int n, int inputSeq[])
{
    for (int i = 1; i <= n; i++)
    {
        yer[i] = -1;
    }
    vector<int> ot;
    for (int i = 0; i < n; i++)
    {
        if (inputSeq[i] <= n)
        {
            if (yer[inputSeq[i]] != -1)
                return 0;
            yer[inputSeq[i]] = i;
        }
        else
        {
            ot.push_back(inputSeq[i]);
        }
    }
    sort(ot.begin(), ot.end());
    int bas = n;
    for (int i : ot)
    {
        if (i != bas + 1)
        {
            return 0;
        }
        else
            bas++;
    }
    int last = 0;
    int deg = 0;
    for (int i = 1; i <= n; i++)
    {
        if (yer[i] == -1)
            continue;
        if (yer[i] < last)
        {
            last = yer[i];
            if (deg)
                return 0;
            deg = 1;
        }
        last = yer[i];
    }

    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    for (int i = 1; i <= n; i++)
    {
        yer[i] = -1;
    }
    vector<int> ot;
    for (int i = 0; i < n; i++)
    {
        if (gondolaSeq[i] <= n)
        {
            if (yer[gondolaSeq[i]] != -1)
                return 0;
            yer[gondolaSeq[i]] = i;
        }
        else
        {
            ot.push_back(gondolaSeq[i]);
        }
    }
    int curi = 0;
    if(ot.size() == n){
        while(curi < n) {
            replacementSeq[curi] = curi + 1;
            curi++;
        }
        return curi;
    }else{
        int piv = 0;
        for(int i = 1; i <= n; i++){
            if(yer[i] != -1){
                piv = i;
                break;
            }
        }
        int last = piv;
        last++;
        last %= n;
        if(!last) last = n;
        for(int j = 1; j < n; j++){
            int idx = yer[piv] + j;
            idx %= n;
            int cur = gondolaSeq[idx];
            if(cur > n){
                replacementSeq[cur - n - 1] = last;
            }else{
                assert(cur == last);
            }
            last++;
            last %= n;
            if(!last) last = n;
        }
        return ot.size();
    }
}

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

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

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:79:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |     if(ot.size() == n){
      |        ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...