結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-11-16 03:39:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,007 bytes |
| コンパイル時間 | 717 ms |
| コンパイル使用メモリ | 56,620 KB |
| 実行使用メモリ | 12,748 KB |
| 最終ジャッジ日時 | 2024-12-31 20:34:22 |
| 合計ジャッジ時間 | 1,690 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d %d", &N, &total);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:11:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | for(int i=0;i<N;i++){scanf("%d", A+i);}
| ~~~~~^~~~~~~~~~~
ソースコード
#include<cstdio>
#include<iostream>
int N, total, A[50];
bool can[50][100001];
char ope[50][100001];
int main(){
scanf("%d %d", &N, &total);
for(int i=0;i<N;i++){scanf("%d", A+i);}
std::fill(&can[0][0], &can[0][0]+50*100001, false);
can[0][A[0]] = true;
for(int i=0;i<N-1;i++){
for(int j=0;j<=total;j++){
if(!can[i][j]){continue;}
if(j * A[i+1] <= total && ope[i+1][j*A[i+1]] != '+'){
can[i+1][j*A[i+1]] = true;
ope[i+1][j*A[i+1]] = '*';
}
if(j + A[i+1] <= total){
can[i+1][j+A[i+1]] = true;
ope[i+1][j+A[i+1]] = '+';
}
}
}
char opes[50];
int length = 0;
for(int i=N-1;i>0;i--){
opes[length++] = ope[i][total];
if(ope[i][total] == '+'){total -= A[i];}
else{total /= A[i];}
}
for(int i=N-2;i>=0;i--){
putchar(opes[i]);
}
puts("");
}
tottoripaper