Submission #936542

#TimeUsernameProblemLanguageResultExecution timeMemory
936542TAhmed33Misspelling (JOI22_misspelling)C++98
28 / 100
46 ms39004 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int add (int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int sub (int a, int b) { a -= b; if (a < 0) a += MOD; return a; } int mul (int a, int b) { return (a * 1ll * b) % MOD; } int dp[300][300][27][2]; int n, m; vector <pair <int, int>> dd[300]; int ans (int pos, int prev, int c, int x) { int &ret = dp[pos][prev][c][x]; if (ret != -1) return ret; bool flag = 1; for (auto j : dd[pos]) { if (j.second == 0) { flag &= (prev >= j.first || x == 0); } else { flag &= (prev >= j.first || x == 1); } } if (!flag) return ret = 0; if (pos == 0) return ret = 1; ret = ans(pos - 1, prev, c, x); for (int i = 0; i < c; i++) { ret = add(ret, ans(pos - 1, pos, i, 0)); } for (int i = c + 1; i < 26; i++) { ret = add(ret, ans(pos - 1, pos, i, 1)); } return ret; } int main () { memset(dp, -1, sizeof(dp)); cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; int l = min(a, b), r = max(a, b); if (a > b) { dd[l - 1].push_back({r, 0}); } else { dd[l - 1].push_back({r, 1}); } } int sum = 0; for (int i = 0; i < 26; i++) { sum = add(sum, ans(n - 1, n + 1, i, 0)); } cout << sum << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...