Cod sursa(job #2733982)

Utilizator MocalinnoMoca Andrei Catalin Mocalinno Data 31 martie 2021 10:54:31
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <bits/stdc++.h>
using namespace std;
void DAU(const string& task = "") {
    if (!task.empty())
        freopen((task + ".in").c_str(), "r", stdin),
        freopen((task + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
void PLEC() {
    exit(0);
}
const int SIGMA(26), MOD(104659);
inline void Add(int& x, const int& y) {
    x += y;
    if (x >= MOD)
        x -= MOD;
}
bool t;
char a, b;
int n, m, res;
int main() {
    DAU("nrcuv");
    vector<vector<bool>> no(SIGMA, vector<bool>(SIGMA));
    cin >> n >> m;
    while (m--) {
        cin >> a >> b;
        a -= 'a', b -= 'a';
        no[a][b] = no[b][a] = true;
    }
    vector<vector<int>> ok(SIGMA);
    for (int i = 0; i < SIGMA; ++i)
        for (int j = 0; j < SIGMA; ++j)
            if (!no[i][j])
                ok[i].emplace_back(j);
    vector<vector<int>> dp(2, vector<int>(SIGMA, 1));
    for (int i = 2; i <= n; ++i) {
        t = !t;
        dp[t] = vector<int>(SIGMA);
        for (int last = 0; last < SIGMA; ++last)
            for (const int& curr : ok[last])
                Add(dp[t][curr], dp[!t][last]);
    }
    for (int i = 0; i < SIGMA; ++i)
        Add(res, dp[t][i]);
    cout << res;
    PLEC();
}