답안 #172526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172526 2020-01-01T20:24:40 Z DS007 곤돌라 (IOI14_gondola) C++14
60 / 100
161 ms 9196 KB
#include <bits/stdc++.h>
#include <gondola.h>
using namespace std;

int valid(int n, int inputSeq[]) {
    set<int> done;
    map<int, int> pos;
    for (int i = 0; i <= n; i++) pos[i] = -1;
    vector<int> a;
    int check = 1;

    for (int i = 0; i < n; i++) {
        if (done.count(inputSeq[i]))
            check = 0;
        done.insert(inputSeq[i]);
        if (inputSeq[i] <= n)
            a.push_back(inputSeq[i]), pos[inputSeq[i]] = i;
    }

    int ind = -1, val = n + 1;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] < val)
            val = a[i], ind = i;
    }

    if (ind == -1)
        return check;

    for (int i = 0, j = ind + 1; i < a.size() - 1; i++, j++) {
        if (j == a.size())
            j = 0;
        assert(j < a.size());
        if (a[j] <= val)
            check = 0;
        val = a[j];
    }

    int last = 1;
    while (last <= n && pos[last] == -1)
        last++;
    for (int i = last + 1; i <= n; i++) {
        assert(i <= n && last <= n);
        if (pos[i] == -1)
            continue;
        if (i - last != pos[i] - pos[last] && i - last != pos[i] + n - pos[last])
            check = 0;
        last = i;
    }

    return check;
}

int initial[100000];
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    int check = -1;
    for (int i = 0; i < n; i++) if (gondolaSeq[i] <= n) check = i;

    if (check == -1) {
        for (int i = 0; i < n; i++) initial[i] = i + 1;
    } else {
        for (int i = 0, j = check, k = gondolaSeq[j]; i < n; i++, j++, k++) {
            if (k == n + 1)
                k = 1;
            if (j == n)
                j = 0;
            initial[j] = k;
        }
    }

    map<int, int> m;
    for (int i = 0; i < n; i++) if (gondolaSeq[i] > n) m[gondolaSeq[i]] = i;

    int last = n + 1, c = 0;
    for (auto i : m) {
        for (; last <= i.first; last++) {
            replacementSeq[c++] = initial[i.second];
            initial[i.second] = last;
        }
    }

    return c;
}

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

/*int gondolaSequence[100001];
int replacementSequence[250001];

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 ", 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;
}*/

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++) {
                     ~~^~~~~~~~~~
gondola.cpp:29:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0, j = ind + 1; i < a.size() - 1; i++, j++) {
                                  ~~^~~~~~~~~~~~~~
gondola.cpp:30:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (j == a.size())
             ~~^~~~~~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from gondola.cpp:1:
gondola.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         assert(j < a.size());
                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 42 ms 4340 KB Output is correct
7 Correct 142 ms 8304 KB Output is correct
8 Correct 88 ms 7668 KB Output is correct
9 Correct 24 ms 2808 KB Output is correct
10 Correct 106 ms 8944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 42 ms 4340 KB Output is correct
7 Correct 142 ms 8256 KB Output is correct
8 Correct 88 ms 7792 KB Output is correct
9 Correct 24 ms 2936 KB Output is correct
10 Correct 105 ms 8864 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 37 ms 3960 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 161 ms 9196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 360 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 12 ms 1400 KB Output is correct
12 Correct 13 ms 1528 KB Output is correct
13 Correct 27 ms 2936 KB Output is correct
14 Correct 12 ms 1400 KB Output is correct
15 Correct 28 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Incorrect 2 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Halted 0 ms 0 KB -