Cod sursa(job #3313615)

Utilizator Andrei1209Andrei Mircea Andrei1209 Data 5 octombrie 2025 15:20:26
Problema Pascal Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>

using namespace std;
ifstream fin("spion.in");
ofstream fout("spion.out");

const int Nmax = 1e5, mod = 100003;
long long fac[Nmax];
int main()
{
    char s;
    int x = 1, y =1, p;
    fin >> p;
    fin.get();

    fin.get(s);
    while ( s != '\n' )
    {
        ++x;
        if ( s == 'E')
            ++y;
        fin.get(s);
    }

    if ( p == 1 )
        fout << y << '\n';
    else
    {
        int i;
        fac[0] = 1;
        for ( i = 1; i <= Nmax; ++i )
            fac[i] = fac[i - 1] * i;

        i = x;
        int j  = x - y + 1;
        --i, --j; /// fromula merge doar pt indexarea de la 0
        int sol = (fac[i] / fac[i - j] / fac[j]) % mod;
        fout << sol << '\n';
    }
    return 0;
}