結果

問題 No.10 +か×か
コンテスト
ユーザー TLwiegehtt
提出日時 2015-07-14 07:52:45
言語 C90(gcc12)
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 667 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 118 ms
コンパイル使用メモリ 32,184 KB
最終ジャッジ日時 2026-02-23 18:43:09
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d", &total);
      |         ^~~~~~~~~~~~~~~~~~~
main.c:14:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |                 scanf("%d", &a[i]);
      |                 ^~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>

char dp[55][100100];

int main(void){
	int p;
	int i,j,n,total;
	int a[55];
	
	scanf("%d", &n);
	scanf("%d", &total);
	
	for(i=0;i<n;i++){
		scanf("%d", &a[i]);
	}
	
	dp[n][total] = 1;
	for(i=n-1;i>=0;i--){
		for(j=0;j<total+1;j++){
			int tmp = j+a[i];
			dp[i][j] = 0;
			
			if( tmp <= total && dp[i+1][tmp]){
				dp[i][j] = 1;
			}
			tmp = j*a[i];
			if( tmp <= total && dp[i+1][tmp]){
				dp[i][j] = 1;
			}
		}
	}
	
	p = a[0];
	for(i=1;i<n;i++){
		if( (p+a[i]) <= total && dp[i+1][p+a[i]] ){ p+=a[i]; printf("+");	continue;	}
		if( (p*a[i]) <= total && dp[i+1][p*a[i]] ){ p*=a[i]; printf("*");	continue;	}
	}
	
	printf("\n");
	
	return 0;
}
0