Cod sursa(job #2553821)

Utilizator petrisorvmyVamanu Petru Gabriel petrisorvmy Data 22 februarie 2020 12:08:20
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <bits/stdc++.h>
#define FILE_NAME "nrcuv"
#define fast ios_base :: sync_with_stdio(0); cin.tie(0);
#pragma GCC optimize("O3")
#define NMAX 1000010
using namespace std;

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef pair<ld,ld> pct;

const ll inf = 1LL << 60;
const int mod = 104659;
const ld eps = 1e-9;


void add(int &a , int b)
{
    a += b;
    a %= mod;
}

void sub(int &a, int b)
{
    a = (a - b + mod) % mod;
}

int n,m, pd[30][1100],ans;
char a,b;
bitset <30> adj[30];
vector <int> poz[30];

int main()
{
    f >> n >> m;
    while(m--)
    {
        f >> a >> b;
        adj[a - 'a'][b - 'a'] = 1;
        adj[b - 'a'][a - 'a'] = 1;
    }
    for(int i = 0; i <= 'z' - 'a'; ++i)
        pd[i][1] = 1;

    for(int i = 2; i <= n; ++i)
            for(int k = 0; k <= 'z' - 'a'; ++k)
        for(int j = 0; j <= 'z' - 'a'; ++j)
                if(!adj[j][k])
                    add(pd[k][i], pd[j][i-1]);

    for(int i = 0; i <= 'z' - 'a'; ++i)
        add(ans, pd[i][n]);
    g << ans;
    f.close();
    g.close();
    return 0;
}