1009B - Minimum Ternary String - CodeForces Solution


greedy implementation *1400

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using str = string;

// Pairs
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<ld,ld>;
#define F first
#define S second

// Vectors
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsor(x) sort(rall(x))
#define pb(x) push_back(x)

// Complex
const ld PI = acos((ld)-1);
const ld EPS = (1e-10);
typedef complex<double>point;

#define angle(x)  (atan2((x).imag(), (x).real()))
#define vec(x,y)  ((y) - (x))
#define length(x) (hypot((x).imag(), (x).real()))
#define normalize(x) ((x)/length(x))
#define dp(x,y) ((conj(x) * (y)).real()) // dot product, if = 0 -> prep
#define cp(x,y) ((conj(x) * (y)).imag()) // cross product, if = 0 -> parallel
#define same(p1,p2) (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define lengthSqr(p)  dp(p,p)
#define Rotate_O(p,ang) ((p) * exp(point(0,ang)))
#define Rotate_A(p,ang,about) (Rotate_O(vec(about,p),ang) + about)
#define Reflect_O(v,m) (conj((v) / (m)) * (m))

// Common
#define endl "\n"
#define E cout << -1 << endl;
#define N cout << "NO" << endl;
#define Y cout << "YES" << endl;
#define SetPre(n, x)  cout << fixed << setprecision(n) << x

// Loops
#define F0R(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR(i, a) F0R(i, 0, a)

// Contest
#define tests int t; cin >> t; while(t--)
#define Sonic ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int main()
{
    Sonic
    string s ; cin >> s ;
    string sol;
    int i = 0 ;
    for( ; i < sz(s) ; i++ ){
        if( s[i] != '2' ) sol += s[i] ;
        else break ;
    }
    int sum0 = 0;
    string MMMMMMMMMMM;
    for( ; i < sz(s) ; i++ ){
        if( s[i] == '1' ) sol+=s[i];
        else MMMMMMMMMMM += s[i];
    }
    sor(sol);
    sol += MMMMMMMMMMM;
    cout<<sol;
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

493D - Vasya and Chess
1485A - Add and Divide
337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour