답안 #12217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
12217 2014-12-25T04:47:37 Z paulsohn 격자 보존하기 (GA9_preserve) C
100 / 100
40 ms 2452 KB
#include<stdio.h>
#include<stdlib.h>

int n, k, d;
int p[100010], Gap[100010], lb, rb, sum, sum2, score;

void mergesort(int* po, int n){
    int *pt, *pt2, *tmp;
    int rm, rm2, h=0, i;

    if(n<2) return;

    pt=po;
    pt2=po+n/2;

    rm=n/2;
    rm2=n-n/2;

    mergesort(pt, rm);
    mergesort(pt2, rm2);

    tmp=(int*) malloc(sizeof(int)*n);

    while(rm && rm2){
        if(*pt>*pt2){
            tmp[h++]=*(pt++);
            rm--;
        }
        else{
            tmp[h++]=*(pt2++);
            rm2--;
        }
    }
    while(rm){
        tmp[h++]=*(pt++);
        rm--;
    }
    while(rm2){
        tmp[h++]=*(pt2++);
        rm2--;
    }
    for(i=0; i<n; i++){
        po[i]=tmp[i];
    }
    free(tmp);
    return;
}

int main(){
    int i, tmp;
    scanf("%d %d %d", &n, &k, &d);
    for(i=0;i<k;i++){
        scanf("%d", &p[i]);
        if(i) Gap[i-1]=p[i]-p[i-1]-1;
    }
    lb=p[0]-1;
    rb=n-p[k-1];
    mergesort(Gap, k-1);

    for(i=0; i<k-1 && i<d/2-1; i++){
        sum+=Gap[i];
    }
    sum2=sum+(k-1<=d/2-1 ? 0 : Gap[d/2-1]);

    tmp=sum2;
    if(score<tmp) score=tmp;
    tmp=(lb>rb?lb:rb)+(d%2?sum2:sum);
    if(score<tmp) score=tmp;
    tmp=lb+rb+sum;
    if(score<tmp) score=tmp;
    printf("%d\n", score);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1868 KB Output is correct
2 Correct 0 ms 1868 KB Output is correct
3 Correct 0 ms 1868 KB Output is correct
4 Correct 0 ms 1868 KB Output is correct
5 Correct 0 ms 1868 KB Output is correct
6 Correct 0 ms 1868 KB Output is correct
7 Correct 0 ms 1868 KB Output is correct
8 Correct 0 ms 1868 KB Output is correct
9 Correct 0 ms 1868 KB Output is correct
10 Correct 0 ms 1868 KB Output is correct
11 Correct 0 ms 1868 KB Output is correct
12 Correct 0 ms 1868 KB Output is correct
13 Correct 0 ms 1868 KB Output is correct
14 Correct 0 ms 1868 KB Output is correct
15 Correct 0 ms 1868 KB Output is correct
16 Correct 0 ms 1868 KB Output is correct
17 Correct 0 ms 1868 KB Output is correct
18 Correct 0 ms 1868 KB Output is correct
19 Correct 0 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 0 ms 1868 KB Output is correct
23 Correct 0 ms 1868 KB Output is correct
24 Correct 0 ms 1868 KB Output is correct
25 Correct 0 ms 1868 KB Output is correct
26 Correct 0 ms 1868 KB Output is correct
27 Correct 0 ms 1868 KB Output is correct
28 Correct 0 ms 1868 KB Output is correct
29 Correct 0 ms 1868 KB Output is correct
30 Correct 0 ms 1868 KB Output is correct
31 Correct 0 ms 1868 KB Output is correct
32 Correct 0 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1868 KB Output is correct
2 Correct 0 ms 1868 KB Output is correct
3 Correct 0 ms 1868 KB Output is correct
4 Correct 0 ms 1868 KB Output is correct
5 Correct 0 ms 1868 KB Output is correct
6 Correct 0 ms 1868 KB Output is correct
7 Correct 0 ms 1868 KB Output is correct
8 Correct 0 ms 1868 KB Output is correct
9 Correct 0 ms 1868 KB Output is correct
10 Correct 0 ms 1868 KB Output is correct
11 Correct 0 ms 1868 KB Output is correct
12 Correct 0 ms 1868 KB Output is correct
13 Correct 0 ms 1868 KB Output is correct
14 Correct 0 ms 1868 KB Output is correct
15 Correct 0 ms 1868 KB Output is correct
16 Correct 0 ms 1868 KB Output is correct
17 Correct 0 ms 1868 KB Output is correct
18 Correct 0 ms 1868 KB Output is correct
19 Correct 0 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 0 ms 1868 KB Output is correct
23 Correct 0 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1868 KB Output is correct
2 Correct 0 ms 1868 KB Output is correct
3 Correct 0 ms 1868 KB Output is correct
4 Correct 0 ms 1868 KB Output is correct
5 Correct 0 ms 1868 KB Output is correct
6 Correct 0 ms 1868 KB Output is correct
7 Correct 0 ms 1868 KB Output is correct
8 Correct 0 ms 1868 KB Output is correct
9 Correct 0 ms 1868 KB Output is correct
10 Correct 0 ms 1868 KB Output is correct
11 Correct 0 ms 1868 KB Output is correct
12 Correct 0 ms 1868 KB Output is correct
13 Correct 0 ms 1868 KB Output is correct
14 Correct 0 ms 1868 KB Output is correct
15 Correct 0 ms 1868 KB Output is correct
16 Correct 0 ms 1868 KB Output is correct
17 Correct 0 ms 1868 KB Output is correct
18 Correct 0 ms 1868 KB Output is correct
19 Correct 0 ms 1868 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 0 ms 1868 KB Output is correct
23 Correct 0 ms 1868 KB Output is correct
24 Correct 0 ms 1868 KB Output is correct
25 Correct 0 ms 1868 KB Output is correct
26 Correct 0 ms 1868 KB Output is correct
27 Correct 0 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2452 KB Output is correct
2 Correct 40 ms 2452 KB Output is correct
3 Correct 36 ms 2452 KB Output is correct
4 Correct 20 ms 2452 KB Output is correct
5 Correct 36 ms 2452 KB Output is correct
6 Correct 28 ms 2452 KB Output is correct
7 Correct 32 ms 2452 KB Output is correct
8 Correct 28 ms 2452 KB Output is correct
9 Correct 20 ms 2060 KB Output is correct
10 Correct 8 ms 1868 KB Output is correct
11 Correct 32 ms 2428 KB Output is correct
12 Correct 36 ms 2436 KB Output is correct
13 Correct 32 ms 2424 KB Output is correct
14 Correct 28 ms 2440 KB Output is correct
15 Correct 28 ms 2444 KB Output is correct
16 Correct 36 ms 2444 KB Output is correct
17 Correct 32 ms 2432 KB Output is correct
18 Correct 24 ms 2428 KB Output is correct
19 Correct 32 ms 2428 KB Output is correct
20 Correct 0 ms 1868 KB Output is correct
21 Correct 0 ms 1868 KB Output is correct
22 Correct 28 ms 2420 KB Output is correct
23 Correct 28 ms 2440 KB Output is correct
24 Correct 36 ms 2440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2452 KB Output is correct
2 Correct 32 ms 2452 KB Output is correct
3 Correct 36 ms 2452 KB Output is correct
4 Correct 32 ms 2452 KB Output is correct
5 Correct 36 ms 2452 KB Output is correct
6 Correct 28 ms 2452 KB Output is correct
7 Correct 28 ms 2452 KB Output is correct
8 Correct 36 ms 2452 KB Output is correct
9 Correct 12 ms 2060 KB Output is correct
10 Correct 12 ms 1868 KB Output is correct
11 Correct 20 ms 2276 KB Output is correct
12 Correct 28 ms 2320 KB Output is correct
13 Correct 28 ms 2328 KB Output is correct
14 Correct 24 ms 2324 KB Output is correct
15 Correct 28 ms 2336 KB Output is correct
16 Correct 20 ms 2372 KB Output is correct
17 Correct 28 ms 2412 KB Output is correct
18 Correct 28 ms 2392 KB Output is correct
19 Correct 28 ms 2312 KB Output is correct
20 Correct 28 ms 2404 KB Output is correct