답안 #250656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250656 2020-07-18T15:24:50 Z kingfran1907 학생 (COCI14_studentsko) C++14
10 / 100
3 ms 512 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long llint;

const int maxn = 5010;
const int inf = 0x3f3f3f3f;

int n, k;
int niz[maxn];
vector< int > v;
int mi[maxn], ma[maxn];
int pos[maxn];

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", niz+i);

    for (int i = 0; i < n; i++) v.push_back(niz[i]);
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
        niz[i] = lower_bound(v.begin(), v.end(), niz[i]) - v.begin();

    memset(mi, inf, sizeof mi);
    for (int i = 0; i < n; i++) {
        int tren = niz[i] / k;
        mi[tren] = min(mi[tren], i);
        ma[tren] = max(ma[tren], i);
        pos[niz[i]] = i;
    }

    int l = n / k;
    int sol = 0;
    for (int i = 0; i < l; i++) {
        int tren = 0;
        int mini = mi[i];
        int maxi = -1;
        int las = -1;

        for (int j = i; j < l; j++) {
            if (mi[j] > maxi) {
                maxi = ma[j];
                tren += k;
                las = j;
            } else break;
        }

        for (int j = 1; j < k; j++) {
            int ac = i * k - j;
            if (ac < 0) break;
            if (pos[ac] < mini) tren++;
            else break;
        }

        for (int j = 0; j < k - 1; j++) {
            int ac = (las + 1) * k + j;
            if (ac >= n) break;

            if (pos[ac] > maxi) tren++;
            else break;
        }
        sol = max(sol, tren);
    }
    printf("%d", n - sol);
    return 0;
}

Compilation message

studentsko.cpp: In function 'int main()':
studentsko.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
studentsko.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", niz+i);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -