結果
問題 |
No.10 +か×か
|
ユーザー |
|
提出日時 | 2024-02-16 19:16:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,057 bytes |
コンパイル時間 | 904 ms |
コンパイル使用メモリ | 69,732 KB |
最終ジャッジ日時 | 2025-02-19 13:31:31 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 7 |
ソースコード
#include <iostream> #include <string> using namespace std; string plusORtimes(int A[], int l, int total) { string result; if (l == 1) { if (total == A[0]) { result = ""; } else { result = "!"; } } else if (total < 1) { result = "!"; } else { if (total % A[l-1]) { result = plusORtimes(A, l - 1, total - A[l-1]) + "+"; } else { string add = plusORtimes(A, l - 1, total - A[l-1]) + "+"; string times = plusORtimes(A, l - 1, total / A[l-1]) + "*"; int cmp = add.compare(times); if (cmp > 0) { result = add; } else { result = times; } } } //cout << "l: " << l << ", total: " << total << ", return " << result << endl; return result; } int main(void) { int N, Total; cin >> N >> Total; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } cout << plusORtimes(A, N, Total) << endl; return 0; }