1327C - Game with Chips - CodeForces Solution


constructive algorithms implementation *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

#define int long long int
#define nl "\n"
#define all(x) x.begin(), x.end()

using namespace std;



void Hck()
{
    int n, m, k;
    cin >> n >> m >> k;
    int k2 = k;
    int kk = k;
    map<pair<int,int>,int> mp;
    string ans = "";
    int mxx = INT_MIN;
    int mxy = INT_MIN;

    while(k2--){
        int a,b;
        cin >> a >> b;
        mxx = max(mxx, a);
        mxy = max(mxy, b);
        mp[{a,b}]++;
    }
    int cnt = 0;
    while(k--){
        int a,b;
        cin >> a >> b;
        if(mp.count({a,b}) && mp[{a,b}] == kk){
            cnt++;
        }
    }
    for(int i = 0; i <= mxx-1; i++){
        ans += 'U';
    }
    for(int i = 0; i <= mxy-1; i++){
        ans += 'L';
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m-1; j++){
            if(i % 2 == 0){
                ans += 'R';
            }
            else
                ans += 'L';
        }
        if(i<n-1)
        ans += 'D';
    }
    if(cnt == kk){
        cout << 0 << nl;
        return;
    }
    // cout << cnt  << " " << k << nl;

    cout << ans.size() << nl;
    cout << ans << nl;

}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt = 1;
    // cin >> tt;
    for (int i = 1; i <= tt; i++)
    {
        Hck();
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1215C - Swap Letters
1251C - Minimize The Integer
1494B - Berland Crossword
295A - Greg and Array
1433E - Two Round Dances
1612D - X-Magic Pair
41B - Martian Dollar
906C - Party
774F - Pens And Days Of Week
598B - Queries on a String
1303B - National Project
1303D - Fill The Bag
1198B - Welfare State
1739B - Array Recovery
1739C - Card Game
1739A - Immobile Knight
1739D - Reset K Edges
817B - Makes And The Product
1452C - Two Brackets
400B - Inna and New Matrix of Candies
870B - Maximum of Maximums of Minimums
1600E - Array Game
1149A - Prefix Sum Primes
277A - Learning Languages
769A - Year of University Entrance
1738A - Glory Addicts
1738C - Even Number Addicts
1064B - Equations of Mathematical Magic
384A - Coder
1738B - Prefix Sum Addicts