結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
mudbdb
|
| 提出日時 | 2015-06-22 22:38:39 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,903 bytes |
| コンパイル時間 | 742 ms |
| コンパイル使用メモリ | 21,632 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-10-07 19:50:33 |
| 合計ジャッジ時間 | 2,044 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 1 |
コンパイルメッセージ
main.c: In function ‘add’:
main.c:36:23: warning: implicit declaration of function ‘mul’ [-Wimplicit-function-declaration]
36 | } else if (1 == mul(i+1, total)) {
| ^~~
main.c: In function ‘main’:
main.c:95:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
95 | scanf("%d", &N);
| ^~~~~~~~~~~~~~~
main.c:96:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
96 | scanf("%d", &Total);
| ^~~~~~~~~~~~~~~~~~~
main.c:98:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
98 | for (i=0; i<N; i++) scanf("%d", &(A[i]));
| ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
int N;
int Total;
int *A = 0;
char *Op = 0;
int max_chk(int i, int total)
{
int rc;
if (total <= Total) {
if (A[i+1] == 1) {
total += A[i+1];
} else {
total *= A[i+1];
}
if (i < N-2) {
rc = max_chk(i+1, total);
} else {
rc = total;
}
} else {
rc = total;
}
return rc;
}
int add(int i, int total)
{
int rc = 0;
if (i < N-1) {
total += A[i+1];
Op[i] = '+';
Op[i+1] = '\0';
if (total == Total) {
if (i == N-2) {
rc = 1;
} else if (1 == mul(i+1, total)) {
rc = 1;
} else {
rc = 0;
}
} else if (total < Total) {
if (Total <= max_chk(i+1, total)) {
if (1 == add(i+1, total)) {
rc = 1;
} else if (1 == mul(i+1, total)) {
rc = 1;
} else {
rc = 0;
}
} else {
rc = 0;
}
} else {
rc = 0;
}
}
return rc;
}
int mul(int i, int total)
{
int rc = 0;
if (i < N) {
total *= A[i+1];
Op[i] = '*';
Op[i+1] = '\0';
if (total == Total) {
if (i == N-2) {
rc = 1;
} else if (1 == mul(i+1, total)) {
rc = 1;
} else {
rc = 0;
}
} else if (total < Total) {
if (Total <= max_chk(i+1, total)) {
if (1 == add(i+1, total)) {
rc = 1;
} else if (1 == mul(i+1, total)) {
rc = 1;
} else {
rc = 0;
}
} else {
rc = 0;
}
} else {
rc = 0;
}
}
return rc;
}
int main()
{
int i;
scanf("%d", &N);
scanf("%d", &Total);
A = (int*)malloc(sizeof(int)*N);
for (i=0; i<N; i++) scanf("%d", &(A[i]));
Op = (char*)malloc(sizeof(char)*N);
if (1 == add(0, A[0])) {
} else if (1 == mul(0, A[0])) {
} else {
Op[0] = '!';
Op[1] = '\0';
}
printf("%s\n", Op);
return 0;
}
mudbdb