結果

問題 No.10 +か×か
ユーザー kaffelunkaffelun
提出日時 2017-08-26 09:43:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 456 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 23,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 17:04:38
合計ジャッジ時間 938 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 13 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:5:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%d %d", &N, &T);
      |         ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:7:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         for(int i = 0; i < N; i++) scanf("%d", A + i);
      |                                    ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
using namespace std;
int main() {
	int N, T, b;
	scanf("%d %d", &N, &T);
	int *A = new int[N];
	for(int i = 0; i < N; i++) scanf("%d", A + i);
	N--;
	int Loop = 1 << N;
	for(b = 0; b < Loop; b++) {
		int S = A[0];
		for(int i = 0; i < N; i++) {
			if(b >> i & 1) S *= A[i + 1];
			else S += A[i + 1];
		}
		if(S == T) break;
	}
	for(int i = 0; i < N; i++) {
		if(b >> i & 1) printf("*");
		else printf("+");
	}
	printf("\n");
	return 0;
}
0