fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <cstring>
  6. #include <deque>
  7. #include <time.h>
  8. #include <stack>
  9. #include <stdio.h>
  10. #include <map>
  11. #include <set>
  12. #include <string>
  13. #include <fstream>
  14. #include <queue>
  15. #define mp make_pair
  16. #define pb push_back
  17. #define PI 3.14159265358979323846
  18. #define MOD 1000000007
  19. #define INF ((ll)1e+15)
  20. #define x1 fldgjdflgjhrthrl
  21. #define x2 fldgjdflgrtyrtyjl
  22. #define y1 fldggfhfghjdflgjl
  23. #define y2 ffgfldgjdflgjl
  24. typedef long long ll;
  25. using namespace std;
  26. ll i,j,n,x,y,m,k,ans,a[6000],b[6000];
  27. vector <ll> f;
  28. string s,t;
  29. pair<ll,ll> solve(ll l, ll r)
  30. {
  31. ll x = 0, y = a[l];
  32. for (int i = l; i < r; i++)
  33. if (b[i] == 1)
  34. x += y, y = a[i+1];
  35. else
  36. y *= a[i+1];
  37. return mp(x,y);
  38. }
  39. int main()
  40. {
  41. cin >> s;
  42. t = "1*";
  43. t.append(s);
  44. t.append("*1");
  45. s = t;
  46. n = s.size();
  47. m = n/2;
  48. for (i = 0; i < n; i+=2)
  49. a[i/2] = s[i] - '0';
  50. for (i = 1; i < n; i+=2)
  51. if (s[i] == '+')
  52. b[i/2] = 1;
  53. else
  54. {
  55. b[i/2] = 2;
  56. f.push_back(i/2);
  57. }
  58. ll max1 = 0;
  59. for (i = 0; i < f.size(); i++)
  60. for (j = i+1; j < f.size(); j++)
  61. {
  62. pair <ll,ll> tmp = solve(0,f[i]);
  63. x = tmp.first, y = tmp.second;
  64. tmp = solve(f[i]+1,f[j]);
  65. y *= tmp.first + tmp.second;
  66. ll xx = a[f[j]];
  67. a[f[j]] = y;
  68. tmp = solve(f[j],m);
  69. max1 = max(max1, x+tmp.first+tmp.second);
  70. a[f[j]] = xx;
  71. }
  72. cout << max1 << endl;
  73. return 0;
  74. }
  75.  
  76.  
Success #stdin #stdout 0s 3328KB
stdin
Standard input is empty
stdout
0