Cod sursa(job #2367736)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 5 martie 2019 12:03:23
Problema Lista lui Andrei Scor 20
Compilator cpp-64 Status done
Runda bv_10 Marime 1.03 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");

const long long mo = 104659;
bool ja[41][41];
long long yeet[2][41];

int conv(char c)
{
    return (c-'a');
}

int curr = 0;
void nuke()
{
    for(int i = 0; i < 26; i++){
        yeet[curr][i] = 1;
    }
}

void ayy()
{
    int prev = curr;
    curr = 1-curr;
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < 26; j++){
            if(!ja[i][j]){
                yeet[curr][j] += yeet[prev][i];
                yeet[curr][j] %= mo;
            }
        }
    }
}

int main()
{
    int s, n;
    fin >> s >> n;
    for(int i = 0; i < n; i++){
        char a, b;
        fin >> a >> b;
        int x = conv(a), y = conv(b);
        ja[x][y] = ja[y][x] = 1;
    }
    nuke();
    for(int i = 1; i < s; i++){
        ayy();
    }
    long long res = 0;
    for(int i = 0; i < 26; i++){
        res += yeet[curr][i];
    }
    res %= mo;
    fout << res;
    return 0;
}