Cod sursa(job #2960445)

Utilizator francescom_481francesco martinut francescom_481 Data 4 ianuarie 2023 13:52:59
Problema Grozavesti Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include<bits/stdc++.h>

using namespace std;

ifstream fin("grozavesti.in");
ofstream fout("grozavesti.out");
#define cin fin
#define cout fout

#define N 200005
#define power 73
#define mod 66666013
#define oo 1e18

struct pereche
{
    char tip;
    int x, y;
};
int v[N], x, n, maxim, poz;
vector < pereche > rez;

int main()
{
    cin >> n;
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= n ; j++)
        {
            cin >> x;
            if(i == j)v[i] = x;
        }
    }
    while(n)
    {
        maxim = 0, poz = 1;
        for(int i = 1 ; i <= n ; i++)
        {
            if(v[i] > maxim)
            {
                maxim = v[i];
                poz = i;
            }
        }
        if(poz != n)
        {
            swap(v[poz],v[n]);
            rez.push_back({'C',poz,n});
            rez.push_back({'L',n,poz});
        }
        n--;
    }
    cout << rez.size() << '\n';
    for(auto t : rez)
    {
        cout << t.tip << " " << t.x << " " << t.y <<  '\n';
    }
    return 0;
}