結果

問題 No.10 +か×か
ユーザー mudbdbmudbdb
提出日時 2015-06-22 22:38:39
言語 C90
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,903 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 22,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 19:03:41
合計ジャッジ時間 1,615 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 0 ms
5,376 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 0 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 639 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]));
      |                       ^~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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;
}
0