Submission #880399

# Submission time Handle Problem Language Result Execution time Memory
880399 2023-11-29T10:35:14 Z MilosMilutinovic Misspelling (JOI22_misspelling) C++14
29 / 100
3887 ms 219732 KB
#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 cksub(int a, int b) {
  return a >= b ? a - b : a - b + md;
}

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]);
    }
  }
  vector<vector<int>> pref(n, vector<int>(A));
  for (int i = 0; i < A; i++) {
    pref[0][i] = dp[0][i];
  }
  auto GetSum = [&](int L, int R, int c) {
    L = max(0, L);
    R = min(R, n - 1);
    if (L > R) {
      return 0;
    }
    return cksub(pref[R][c], (L == 0 ? 0 : pref[L - 1][c]));
  };
  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);
      }
    }
    {
      int total = 0;
      for (int c = 0; c < A; c++) {
        total = ckadd(total, GetSum(max(mx_a, mx_b) + 1, i - 1, c));
      }
      for (int j = max(mx_a, mx_b) + 1; j < i; j++) {
        for (int c = 0; c < A; c++) {
          dp[i][c] = ckadd(dp[i][c], cksub(total, GetSum(max(mx_a, mx_b) + 1, i - 1, c)));
        }
      }
    }
    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 j = 0; j < A; j++) {
      pref[i][j] = ckadd(pref[i - 1][j], dp[i][j]);
    }
    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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 939 ms 219596 KB Output is correct
6 Correct 1387 ms 219732 KB Output is correct
7 Correct 1236 ms 219632 KB Output is correct
8 Correct 925 ms 219660 KB Output is correct
9 Correct 1378 ms 219628 KB Output is correct
10 Correct 26 ms 9052 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3887 ms 219624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -