Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- bool dig(char x){
- int k = x - '0';
- return k >= 0 && k < 10;
- }
- bool sh=0;
- void see(vector <pair <int, char> > v){
- for (auto p: v){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s;
- cin>>s;
- vector <pair <int, char> > v;
- int n = s.size();
- int id=0;
- while (id < n){
- string nmb="";
- while (id < n && dig(s[id]) ){
- nmb += s[id];
- id++;
- }
- ll k;
- if (nmb == ""){
- k = 1;
- }
- else{
- k = stoll(nmb);
- }
- char l = s[id];
- v.push_back({k,l});
- id++;
- }
- if (sh){
- see(v);
- }
- n = v.size();
- vector <ll> pf(n);
- pf[0] = v[0].first;
- for (int i = 1; i < n; ++i){
- pf[i] = pf[i-1] + v[i].first;
- }
- //-->min : 2 x
- //union
- int xmn=-1;
- vector <pair <ll, int> > un; //union: {-dif, x}
- if (sh){
- cout<<"Un filling\n";
- }
- for (int i = 0; i <= n - 3; ++i){
- if (v[i].second == v[i+2].second && v[i+1].first == 1){//!!!
- ll bef, aft, dlt;
- bef = to_string(v[i].first).size() + to_string(v[i+2].first).size() + 3;
- aft = to_string(v[i].first + v[i+2].first).size() + 1;
- dlt = bef - aft;
- un.push_back({dlt, pf[i] + 1});
- if (sh){
- cout<<"i = "<<i<<"\n";
- cout<<"bef = "<<bef<<"\n";
- cout<<"aft = "<<aft<<"\n";
- cout<<"dlt = "<<dlt<<"\n";
- }
- }
- }
- sort(un.begin(), un.end());
- reverse(un.begin(), un.end());
- if (!un.empty()){
- if (sh){
- cout<<"un is NOT EMPTY\n";
- for (auto p: un){
- cout<<p.first<<' '<<p.second<<"\n";
- }cout<<"\n";
- }
- xmn = un[0].second;
- }
- else{
- if (sh) cout<<"un empty\n";
- for (int i = 0; i < n; ++i){
- int k = v[i].first;
- int lg = log10(k);
- if (k == 1 || k == pow(10, lg) || k == 2){
- xmn = pf[i];//?
- break;
- }
- }
- }
- vector <ll> ansmn = {2, xmn};
- //-->max: 1 x z
- //ruin
- vector <char> ltr = {'A', 'G', 'C', 'T'};
- char t;//разделительная буква
- int xmx = -1;
- vector < pair <ll, int> > ru;
- if (sh){
- cout<<"RU filling\n";
- }
- for (int i = 0; i < n; ++i){
- if (v[i].first >= 2){
- //находим оптим a,b
- ll a,b, ab = v[i].first;
- int lg = log10(ab);
- for (int r = 0; r < 4; ++r){
- if (ltr[r] != v[i].second){
- t = ltr[r];
- }
- }
- ll A,B,C,D;
- A = pow(10, lg);
- B = ab - A;
- C = ab / 2;
- D = ab - C;
- ll one = to_string(A).size() + to_string(B).size();
- if (A == 1){
- one--;
- }
- if (B == 1){
- one--;
- }
- ll two = to_string(C).size() + to_string(D).size();
- if (C == 1){
- two--;
- }
- if (D == 1){
- two--;
- }
- if (one > two){//перессмотреть!!Избежать случая, где остается единичка!
- a = A;
- b = B;
- }
- else{
- a = C;
- b = D;
- }
- ll bef, aft, dlt;
- bef = to_string(ab).size() + 1;
- aft = to_string(a).size() + to_string(b).size() + 3;
- if (a == 1){
- aft--;
- }
- if (b == 1){
- aft--;
- }
- dlt = aft - bef;
- xmx = a;
- if (i > 0){
- xmx += pf[i-1];
- }
- ru.push_back({dlt, xmx});
- if (sh){
- cout<<"i = "<<i<<"\n";
- cout<<" A B C D = "<<A<<' '<<B<<' '<<C<<' '<<D<<"\n";
- }
- }
- }
- sort(ru.begin(), ru.end());
- reverse(ru.begin(), ru.end());
- if (!ru.empty()){
- if (sh){
- cout<<"ru IS NOT EMPTY\n";
- for (auto p: ru){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- }
- xmx = ru[0].second;
- }
- else{
- if (sh) cout<<"ru empty\n";
- for (int i = 0; i < n; ++i){
- ll k = v[i].first;
- int lg = log10(k);
- if ( k + 1 == pow(10, lg + 1) || k == 1){
- xmx = pf[i];
- t = v[i].second;
- break;
- }
- }
- }
- if (sh){
- cout<<"ans min\n";
- }
- cvl(ansmn);
- if (sh){
- cout<<"ans max\n";
- }
- cout<<1<<' '<<xmx<<' '<<t<<"\n";
- }
- /*
- 5AC5A2C
- 2AC5A2C
- AG1111111GA999C
- 2 1
- 1 1000002 T
- */
Add Comment
Please, Sign In to add comment