Cod sursa(job #1820039)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 1 decembrie 2016 03:28:40
Problema Lista lui Andrei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <iostream>
#include <fstream>
#include <algorithm>

#define LLI long long int
#define N 2005

using namespace std;

ifstream f ("nrcuv.in");
ofstream g ("nrcuv.out");

LLI const MODULO = 104659;

LLI numberExceptions, totalLetters;

pair <char, char> Pair[N];

/*LLI pow1( LLI number, LLI power ){
    if ( power == 0 )
        return 1;
    if ( power == 1 )
        return number;
    if ( power % 2 )
        return ( pow1( number*number, (power-1) / 2) * number);
    else
        return pow1( number*number, power/2);
}*/
LLi pow1(LLi x,LLi y)
{
    LLi p=1;
    while(y>0)
    {
        if(y%2!=0)
        {
            p=p*x;
        }
        x=x*x;
        y=y/2;
    }
    return p;
}

inline void readVariables(void){
    f >> totalLetters >> numberExceptions;
    for ( int index = 0; index < numberExceptions; index++ ){
        f >> Pair[index].first >> Pair[index].second;
        if ( Pair[index].first > Pair[index].second )
            swap (Pair[index].first, Pair[index].second);
    }
}

inline void solveProblem(){
    sort (Pair, Pair+numberExceptions);

    LLI contor = 0;
    for ( int index = 0; index < numberExceptions; index++ ){
        if ( Pair[index] != Pair[index-1] ){
            contor++;
            if ( Pair[index].first != Pair[index].second ){
                contor++;
            }
        }
    }
    g << (pow1(26, totalLetters) - (pow1(26, totalLetters-2) * (totalLetters - 1) * contor) ) % MODULO;
}

int main(){
    readVariables();
    solveProblem();
    return 0;
}