Submission #880396

#TimeUsernameProblemLanguageResultExecution timeMemory
880396MilosMilutinovicMisspelling (JOI22_misspelling)C++14
28 / 100
4091 ms159880 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);
  multiset<int> sa, sb;
  vector<vector<vector<int>>> qs(n, vector<vector<int>>(2));
  for (int i = 0; i < m; i++) {
    if (a[i] == b[i]) {
      continue;
    }
    if (a[i] < b[i]) {
      sa.insert(a[i]);
      qs[b[i]][0].push_back(a[i]);
    }
    if (a[i] > b[i]) {
      sb.insert(b[i]);
      qs[a[i]][1].push_back(b[i]);
    }
  }
  for (int i = 1; i < n; i++) {
    int mx_a = -1;
    int mx_b = -1;
    if (!sa.empty()) {
      auto it = sa.lower_bound(i);
      if (it != sa.begin()) {
        mx_a = *prev(it);
      }
    }
    if (!sb.empty()) {
      auto it = sb.lower_bound(i);
      if (it != sb.begin()) {
        mx_b = *prev(it);
      }
    }
    for (int j = max(mx_a, mx_b) + 1; j < i; j++) {
      for (int c = 0; c < A; c++) {
        for (int cc = 0; cc < A; cc++) {
          if (c == cc) {
            continue;
          }
          dp[i][c] = ckadd(dp[i][c], dp[j][cc]);
        }
      }
    }
    if (mx_a <= mx_b) {
      for (int j = mx_a + 1; j <= mx_b; j++) {
        for (int c = 0; c < A; c++) {
          for (int cc = c + 1; cc < A; cc++) {
            dp[i][cc] = ckadd(dp[i][cc], dp[j][c]);
          }
        }
      }
    } else {
      for (int j = mx_b + 1; j <= mx_a; j++) {
        for (int c = 0; c < A; c++) {
          for (int cc = 0; cc < c; cc++) {
            dp[i][cc] = ckadd(dp[i][cc], dp[j][c]);
          }
        }
      }
    }
    /* for (int c = 0; c < A; c++) {
      for (int j = min(mx_a, mx_b) + 1; 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]);
          }
        }
      }
    } */
    for (int v : qs[i][0]) {
      sa.erase(sa.find(v));
    }
    for (int v : qs[i][1]) {
      sb.erase(sb.find(v));
    }
  }
  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...