Submission #2209063


Source Code Expand

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}




/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}

/*int struct_ascending_compare(const void *p, const void *q) {
    return ((structname*)p)->member - ((strcutname*)q)->member;
}*/


int field[3][3];
int tate[3][2];
int yoko[2][3];
int total;

int dfs(int level){
    int chokudai = 0;
    if (level == 9){
        for (int i = 0; i < 3; i++){
            for (int j = 0; j < 2; j++){
                if (field[i][j] == field[i][j+1]){
                    chokudai += tate[i][j];
                }
            }
        }
        for (int i = 0; i < 2; i++){
            for (int j = 0; j < 3; j++){
                if (field[i][j] == field[i+1][j]){
                    chokudai += yoko[i][j];
                }
            }
        }
        return chokudai;
    }

    //空いているマスにlevelに応じて書き込む
    int tmp;
    int max = -1;
    int min = total + 1;
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            if (field[i][j] == 0){
                if (level % 2){
                    field[i][j] = -1;
                    tmp = dfs(level+1);
                    field[i][j] = 0;
                    min = min>tmp?tmp:min;
                }else{
                    field[i][j] = 1;
                    tmp = dfs(level+1);
                    field[i][j] = 0;
                    max = max<tmp?tmp:max;
                }
            }
        }
    }
    if (level % 2){
        return min;
    }else{
        return max;
    }
}

int dp[5005];
int a[5005];
int n, k;

int check(int mid){
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;

    for (int i = 0; i < n; i++){
        for (int j = 5000; j >= 0; j--){
            if (i != mid && j - a[i] >= 0 && dp[j-a[i]]){
                dp[j] = 1;
                if (i != mid && dp[j-a[i]] && j < k && j >= k-a[mid]) return 0;
            }
        }
    }

    return 1;
}


int main(void){
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    qsort(a, n, sizeof(int), ascending_compare);

    int ng, mid, ok;
    ok = n, ng = -1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (check(mid)){
            ng = mid;
        }else{
            ok = mid;
        }
    }
    printf("%d\n", ng+1);
}

Submission Info

Submission Time
Task D - No Need
User Morifo
Language C (Clang 3.8.0)
Score 0
Code Size 4252 Byte
Status WA
Exec Time 581 ms
Memory 256 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 0 / 300 0 / 300
Status
AC × 3
AC × 18
WA × 8
AC × 37
WA × 14
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
Subtask 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 128 KB
0_001.txt AC 1 ms 128 KB
0_002.txt AC 1 ms 256 KB
1_003.txt WA 1 ms 256 KB
1_004.txt WA 1 ms 128 KB
1_005.txt WA 1 ms 128 KB
1_006.txt AC 1 ms 128 KB
1_007.txt AC 1 ms 128 KB
1_008.txt AC 22 ms 252 KB
1_009.txt AC 25 ms 252 KB
1_010.txt WA 18 ms 252 KB
1_011.txt WA 18 ms 252 KB
1_012.txt WA 24 ms 252 KB
1_013.txt WA 24 ms 252 KB
1_014.txt WA 29 ms 252 KB
1_015.txt AC 2 ms 252 KB
1_016.txt AC 1 ms 256 KB
1_017.txt AC 1 ms 128 KB
1_018.txt AC 1 ms 256 KB
1_019.txt AC 10 ms 252 KB
1_020.txt AC 1 ms 252 KB
1_021.txt AC 2 ms 252 KB
1_022.txt AC 3 ms 256 KB
1_023.txt AC 2 ms 128 KB
1_024.txt AC 12 ms 252 KB
1_025.txt AC 18 ms 252 KB
2_026.txt WA 1 ms 256 KB
2_027.txt AC 1 ms 256 KB
2_028.txt AC 1 ms 128 KB
2_029.txt AC 536 ms 256 KB
2_030.txt AC 581 ms 252 KB
2_031.txt WA 318 ms 252 KB
2_032.txt WA 318 ms 252 KB
2_033.txt WA 318 ms 252 KB
2_034.txt WA 318 ms 252 KB
2_035.txt WA 423 ms 252 KB
2_036.txt AC 11 ms 252 KB
2_037.txt AC 1 ms 128 KB
2_038.txt AC 1 ms 128 KB
2_039.txt AC 1 ms 256 KB
2_040.txt AC 75 ms 256 KB
2_041.txt AC 9 ms 252 KB
2_042.txt AC 11 ms 252 KB
2_043.txt AC 84 ms 252 KB
2_044.txt AC 79 ms 252 KB
2_045.txt AC 17 ms 252 KB
2_046.txt AC 286 ms 252 KB
2_047.txt AC 99 ms 252 KB
2_048.txt AC 267 ms 252 KB
2_049.txt AC 189 ms 252 KB
2_050.txt AC 213 ms 252 KB