結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  ReERishun | 
| 提出日時 | 2020-03-27 04:50:09 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,675 bytes | 
| コンパイル時間 | 283 ms | 
| コンパイル使用メモリ | 27,856 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2025-01-02 08:03:15 | 
| 合計ジャッジ時間 | 1,193 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 WA * 13 | 
コンパイルメッセージ
main.c: In function ‘main’:
main.c:28:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         scanf("%d", &dataNum);
      |         ^~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include<stdio.h>
#include <stdlib.h>
#define true 1
#define false 0
// 組み合わせ探索関数
int combi(int gauge, int data[1000], int cursor) {
	for (int i = cursor; data[i] != 0; i++) {
		if (gauge - data[i] == 0)
			return true;
		else if (gauge - data[i] > 0)
			if (combi(gauge - data[i], data, i + 1))
				return true;
	}
	return false;
}
int main() {
	int dataNum = 0;
	int data[1000];
	char str;
	int total = 0;
	int harf = 0;
	// データの数を取得
	scanf("%d", &dataNum);
	// 配列初期化
	for (int i = 0; i < dataNum; i++)
		data[i] = 0;
	// 数値取得
	for (int i = 0; str != '\n'; ) {
		str = getchar();
		if (str == '\0')
			i++;
		else
			data[i] = data[i] * 10 + (int)str - (int)'0';
	}
	// 合計値を求める
	for (int i = 0; i < dataNum; i++)
		total += data[i];
	// 偶数でない場合はimpossible
	if (total % 2 == 0)
		goto impossible;
	// 半分の値を求める
	harf = total / 2;
	// 半分の値を超える値があるか
	for (int i = 0; i < dataNum; i++) {
		if (data[i] > harf)
			goto impossible;
		else if (data[i] == harf)
			goto possible;
	}
	
	// 配列のソート
	int cnt = 0;
	int put = 0;
	int flg = 0;
	while (true) {
		if (data[cnt] < data[cnt + 1]) {
			put = data[cnt];
			data[cnt] = data[cnt + 1];
			data[cnt + 1] = put;
			flg = true;
		}
		cnt++;
		if (cnt >= dataNum - 1) {
			if (flg)
				cnt = flg = 0;
			else
				break;
		}
	}
	// 組み合わせの探索
	if (combi(harf, data, 0))
		goto possible;
	else
		goto impossible;
possible:	// 組み合わせがある場合
	printf("possible");
	return 0;
impossible:	// 組み合わせがない場合
	printf("impossible");
	return 0;
}
            
            
            
        