Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- void solve(){
- int t;
- cin >> t;
- while(t--){
- int n;
- string s;
- cin >> n >> s;
- bool q = false;
- if (count(s.begin(), s.end(), '0') > 0) q = true;
- int ans = 1e18;
- if(n == 2){
- cout << (int)(s[0] - '0') * 10 + (int)(s[1]-'0') << '\n';
- }else if((q && n >= 4) || (q && n == 3 && s[0] == '0') || s[2] == '0'){
- cout << "0\n";
- }else{
- for(int i = 0; i < n - 1; ++i){
- vector<int> sum;
- for(int j = 0; j < n; ++j){
- if(j == i){
- sum.push_back((int)(s[j] - '0') * 10 + (int)(s[j + 1] - '0'));
- ++j;
- }else{
- sum.push_back((int)(s[j] - '0'));
- }
- }
- for(int j = 1; j < sum.size(); ++j){
- sum[0] = min(sum[0] + sum[j], sum[0] * sum[j]);
- }
- ans = min(ans, sum[0]);
- }
- cout << ans << '\n';
- }
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement