結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-05-06 14:12:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 704 bytes |
| コンパイル時間 | 133 ms |
| コンパイル使用メモリ | 22,784 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 09:11:31 |
| 合計ジャッジ時間 | 962 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%d", &w[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
// どうしてこの解法を思いつけなかったんだろう...
int judge();
int n, w[100], table[5001];
int main(void) {
scanf("%d", &n);
int i;
for(i = 0; i < n; i++) {
scanf("%d", &w[i]);
}
printf("%s%s\n", judge() ? "" : "im", "possible");
return 0;
}
int judge() {
int sum = 0, i, j;
for(i = 0; i < n; i++) {
sum += w[i];
}
if(sum % 2) { return 0; }
int half = sum / 2;
table[0] = 1;
for(i = 0; i < n; i++) {
if(w[i] == half) { return 1; }
for(j = 0; j < half; j++) {
if(0 < table[j] && table[j] < i + 2) {
int v = j + w[i];
if(v == half) { return 1; }
if(v < half && table[v] == 0) { table[v] = i + 2; }
}
}
}
return 0;
}
FF256grhy