結果

問題 No.4 おもりと天秤
ユーザー Fre_de_ricaFre_de_rica
提出日時 2019-03-07 21:01:50
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,578 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 29,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:28:20
合計ジャッジ時間 1,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main(void){
    
    int array_num = 10000;
    int array[array_num];
    int array_tmp[array_num];
    
    int in;
    int num;
    int target;
    int cnt;
    int array_tmp_sfx;
    
    array[0] = 0;
    array_tmp[0] = 0;
    target = 0;
    array_tmp_sfx = 0;
    
    for(int i=1;i<array_num; i++){
        array[i] = -1;
        array_tmp[i] = 0;
    }
    
    scanf("%d", &in);
    
    for(int i=0; i<in; i++){
        scanf("%d", &array_tmp[i]);
        target += array_tmp[i];
    }
    
    if(target%2 != 0){
        printf("impossible\n");
        return 0;
    }
    
    target = target/2;
    
    while(in--){
        
        cnt = array_num;
        
        num = array_tmp[array_tmp_sfx];
        array_tmp_sfx++;
        
        while(1){
            
            if(array[cnt] != -1 && array[cnt + num] == -1 ){
                
                array[cnt+num] = num; 
            }
            
            if(cnt == 0){
                break;
            }
            cnt--;
        }
    }
    
    if(array[target] == -1){
        printf("impossible\n");
    }
    if(array[target] != -1){
        printf("possible\n");
    }
    
/* debug 
 int sum = 0;
    while(1){
        
        sum += array[target];
        
        if(target == 0){
           printf("array[%d] => %d, sum => %d\n", target, array[target], sum ); 
           
           break;
        }
        
        printf("array[%d] => %d, sum => %d\n", target, array[target], sum );
        target = target - array[target];
        
    }
*/
    return 0;
}
0