99B - Help Chef Gerasim - CodeForces Solution


implementation sortings *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>



using namespace std;



#define pb push_back

#define eb emplace_back

#define f first

#define s second

#define deb(a) cerr << #a << " = " << a << "\n";

#define all(x) (x).begin(), (x).end()

#define file() { ifstream cin("input.txt"); ofstream cout("output.txt"); }

#define correct(x, y, n, m) (0 <= (x) && (x) < (n) && 0 <= (y) && (y) < (m))

#define y1 y1212312

#define int long long



typedef long long ll;

typedef long double ld;

typedef pair <int, int> pii;



const ll INF = 2e18;

const ll mod = 1e9 + 7;

const int inf = 1e9;

const ld EPS = 1e-12;

const ld Pi = acosl(-1);

const int P = 31;

const int dx[2] = {0, 1};

const int dy[2] = {1, 0};



int qqq = 1;



mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



int n;



void solve() {

    cin >> n;

    vector <int> a(n);

    map <int, int> mp, ind;

    for (int i = 0; i < n; i++) {

        cin >> a[i];

        mp[a[i]]++;

        ind[a[i]] = i;

    }



    if (n == 2) {

        int delta = abs(a[1] - a[0]);

        if (delta % 2) {

            cout << "Unrecoverable configuration.\n";

            return;

        }

        if (delta == 0) {

            cout << "Exemplary pages.\n";

            return;

        }

        cout << delta / 2 << " ml. from cup #" << (a[1] > a[0] ? 1 : 2) << " to cup #" << (a[1] > a[0] ? 2 : 1) << ".\n";

        return;

    }



    sort(a.begin(), a.end());

    a.resize(unique(a.begin(), a.end()) - a.begin());



    if ((int)a.size() == 1) {

        cout << "Exemplary pages.\n";

        return;

    }





    if ((int)a.size() != 3) {

        cout << "Unrecoverable configuration.\n";

        return;

    }



    if (mp[a[0]] != 1 || mp[a[1]] != n - 2 || mp[a[2]] != 1) {

        cout << "Unrecoverable configuration.\n";

        return;

    }



    if (a[1] - a[0] != a[2] - a[1]) {

        cout << "Unrecoverable configuration.\n";

        return;

    }



    int delta = a[1] - a[0];

    cout << delta << " ml. from cup #" << ind[a[0]] + 1 << " to cup #" << ind[a[2]] + 1 << ".\n";

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    clock_t tStart = clock();

    //cin >> qqq;

    while (qqq--) {

        solve();

    }

    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';

    return 0;

}


Comments

Submit
0 Comments
More Questions

1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)
2148. Count Elements With Strictly Smaller and Greater Elements
2149. Rearrange Array Elements by Sign
2150. Find All Lonely Numbers in the Array
2151. Maximum Good People Based on Statements
2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range