結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
ReERishun
|
| 提出日時 | 2020-03-27 05:19:43 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,731 bytes |
| コンパイル時間 | 584 ms |
| コンパイル使用メモリ | 27,648 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-01-02 08:06:46 |
| 合計ジャッジ時間 | 3,481 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 RE * 18 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:61:16: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
61 | printf(__LINE__);
| ^~~~~~~~
| |
| int
In file included from /usr/include/stdio.h:980,
from main.c:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:84:32: note: expected ‘const char * restrict’ but argument is of type ‘int’
84 | printf (const char *__restrict __fmt, ...)
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
main.c:61:9: warning: format not a string literal and no format arguments [-Wformat-security]
61 | printf(__LINE__);
| ^~~~~~
main.c:83:16: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
83 | printf(__LINE__);
| ^~~~~~~~
| |
| int
/usr/include/x86_64-linux-gnu/bits/stdio2.h:84:32: note: expected ‘const char * restrict’ but argument is of type ‘int’
84 | printf (const char *__restrict __fmt, ...)
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
main.c:83:9: warning: format not a string literal and no format arguments [-Wformat-security]
83 | printf(__LINE__);
| ^~~~~~
main.c:27:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d\n", &dataNum);
| ^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.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 = '\0';
int total = 0;
int harf = 0;
// データの数を取得
scanf("%d\n", &dataNum);
// 配列初期化
for (int i = 0; i < dataNum; i++)
data[i] = 0;
// 数値取得
for (int i = 0; str != '\n'; ) {
str = getchar();
if (str == ' ')
i++;
else if(str >= '0' && str <= '9')
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;
}
printf(__LINE__);
// 配列のソート
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;
}
}
printf(__LINE__);
// 組み合わせの探索
if (combi(harf, data, 0))
goto possible;
else
goto impossible;
possible: // 組み合わせがある場合
printf("possible");
return 0;
impossible: // 組み合わせがない場合
printf("impossible");
return 0;
}
ReERishun