Submission #880384

#TimeUsernameProblemLanguageResultExecution timeMemory
880384MilosMilutinovicMisspelling (JOI22_misspelling)C++14
28 / 100
4078 ms77300 KiB
#include <bits/stdc++.h>

using namespace std;

const int md = 1e9 + 7;

int ckadd(int a, int b) {
  return a + b >= md ? a + b - md : a + b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    --a[i]; --b[i];
  }
  const int A = 26;
  vector<vector<int>> dp(n, vector<int>(A));
  dp[0] = vector<int>(A, 1);
  for (int i = 1; i < n; i++) {
    int mx_a = -1;
    for (int j = 0; j < m; j++) {
      if (a[j] == b[j]) {
        continue;
      }
      if (a[j] <= b[j] && b[j] >= i && a[j] < i) {
        mx_a = max(mx_a, a[j]);
      }
    }
    int mx_b = -1;
    for (int j = 0; j < m; j++) {
      if (a[j] == b[j]) {
        continue;
      }
      if (a[j] >= b[j] && a[j] >= i && b[j] < i) {
        mx_b = max(mx_b, b[j]);
      }
    }
    for (int c = 0; c < A; c++) {
      for (int j = 0; j < i; j++) {
        for (int cc = 0; cc < A; cc++) {
          if (c == cc) {
            continue;
          }
          bool ok = true;
          if (cc < c && j <= mx_a) {
            ok = false;
          }
          if (cc > c && j <= mx_b) {
            ok = false;
          }
          if (ok) {
            dp[i][c] = ckadd(dp[i][c], dp[j][cc]);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < A; j++) {
      ans = ckadd(ans, dp[i][j]);
    }
  }
  cout << ans << '\n';
  return 0;
}
#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...