Advertisement
Goga21

Untitled

Jun 23rd, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. void solve(){
  8. int t;
  9. cin >> t;
  10. while(t--){
  11.  
  12. int n;
  13. string s;
  14.  
  15. cin >> n >> s;
  16.  
  17. bool q = false;
  18.  
  19. if (count(s.begin(), s.end(), '0') > 0) q = true;
  20.  
  21. int ans = 1e18;
  22.  
  23. if(n == 2){
  24. cout << (int)(s[0] - '0') * 10 + (int)(s[1]-'0') << '\n';
  25. }else if((q && n >= 4) || (q && n == 3 && s[0] == '0') || s[2] == '0'){
  26. cout << "0\n";
  27. }else{
  28. for(int i = 0; i < n - 1; ++i){
  29. vector<int> sum;
  30.  
  31. for(int j = 0; j < n; ++j){
  32. if(j == i){
  33. sum.push_back((int)(s[j] - '0') * 10 + (int)(s[j + 1] - '0'));
  34. ++j;
  35. }else{
  36. sum.push_back((int)(s[j] - '0'));
  37. }
  38. }
  39.  
  40. for(int j = 1; j < sum.size(); ++j){
  41. sum[0] = min(sum[0] + sum[j], sum[0] * sum[j]);
  42. }
  43. ans = min(ans, sum[0]);
  44. }
  45.  
  46. cout << ans << '\n';
  47. }
  48. }
  49. }
  50.  
  51. signed main() {
  52. ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  53. solve();
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement