結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2015-07-16 00:27:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,217 bytes |
| コンパイル時間 | 660 ms |
| コンパイル使用メモリ | 74,876 KB |
| 実行使用メモリ | 21,736 KB |
| 最終ジャッジ日時 | 2024-07-08 08:06:40 |
| 合計ジャッジ時間 | 1,202 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d%d",&n,&total);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:33:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d",&A[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define SIZE 10000
int dp[51][100000]; //1..* 2..+
int main(){
int n,total;
int A[SIZE];
string ans;
scanf("%d%d",&n,&total);
for(int i=0;i<n;i++)
scanf("%d",&A[i]);
dp[1][A[0]]=1;
for(int i=1;i<n;i++){
for(int j=0;j<=total;j++){
if(dp[i][j]==0) continue;
if(j*A[i]<=total){
dp[i+1][j*A[i]]=max(dp[i+1][j*A[i]],1);
}
if(j+A[i]<=total){
dp[i+1][j+A[i]]=max(dp[i+1][j+A[i]],2);
}
}
}
for(int i=n;i>=2;i--){
if(dp[i][total]==1){
ans+='*';
total/=A[i-1];
}else{
ans+='+';
total-=A[i-1];
}
}
reverse(ans.begin(),ans.end());
cout << ans << endl;
return 0;
}
goodbaton