Cod sursa(job #872680)

Utilizator mazaandreiAndrei Mazareanu mazaandrei Data 6 februarie 2013 14:52:08
Problema Lista lui Andrei Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<fstream>
#include<set>
#define mod 104659
using namespace std;
struct pereche {int a, b;};
int k,p,s,n,m,x,y,l;
char a,b;
struct cmp{
bool operator()(pereche x, pereche y){
    if(x.a<y.a) return 1;
    if(x.a==y.a && x.b<y.b) return 1;
    return 0;
}
};
set <pereche, cmp> s2;
set <int> s1;
int main(){
    ifstream in("nrcuv.in"); ofstream out("nrcuv.out");
    in>>n>>m;
    for(int i=1;i<=m;++i){
        in>>a>>b; x=a-'a'; y=b-'a';
        if(x<y) s2.insert((pereche){x,y});
        if(x>y) s2.insert((pereche){y,x});
        if(x==y) s1.insert(x);
    }
    k=s2.size(); l=s1.size();
    //26^n -k*(n-1)*2-p*(n-1);
    x=26; y=n; p=1;
    while(y>=1){
        if(y%2==1) p=(p*x)%mod;
        x=(x*x)%mod; y/=2;
    }
    p=p%mod;
    p=p-k*(n-1)*2-l*(n-1);
    while(p<=0) p+=mod;

    out<<p%mod<<'\n';

    return 0;
}