QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#772761#9536. Athlete Welcome CeremonyluishghCompile Error//C++203.3kb2024-11-22 21:39:322024-11-22 21:39:32

Judging History

This is the latest submission verdict.

  • [2024-11-22 21:39:32]
  • Judged
  • [2024-11-22 21:39:32]
  • Submitted

answer

#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

#define int ll

const int MOD  = 1e9 + 7;

ll add(ll a, ll b) {
  ll r = a + b;
  if (r >= MOD) r -= MOD;
  return r;
}

const int MAX = 300 + 10;
//const int MAX = 10;

ll dp[MAX][MAX][MAX][3];

signed main() {_

//cout << "entrou" << endl;

  int n, q; cin >> n >> q;

  string s; cin >> s;

  int tot = n;

  for (auto c : s) if (c != '?') tot--;

  // dp[i][b][c][last] = dp[i+1][b-1][c][b] + dp[i+1][b][c-1][last]

  memset(dp, 0, sizeof dp);
  //cout << "memsetou" << endl;

  dp[n][0][0][0] = 1;
  dp[n][0][0][1] = 1;
  dp[n][0][0][2] = 1;

  int cnt = 0;

  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '?') cnt++;
    for (int b = 0; b <= n; b++) {
      for (int c = 0; c <= n; c++) {
        if (b + c > cnt) continue;
        int a = cnt - b - c;

        if (s[i] == 'a') {
          dp[i][b][c][0] = 0;
          dp[i][b][c][1] = dp[i+1][b][c][0];
          dp[i][b][c][2] = dp[i+1][b][c][0];
        } else if (s[i] == 'b') {
          dp[i][b][c][0] = dp[i+1][b][c][1];
          dp[i][b][c][1] = 0;
          dp[i][b][c][2] = dp[i+1][b][c][1];
        } else if (s[i] == 'c') {
          dp[i][b][c][0] = dp[i+1][b][c][2];
          dp[i][b][c][1] = dp[i+1][b][c][2];
          dp[i][b][c][2] = 0;
        } else {
          for (int last = 0; last < 3; last++) {
            auto & pdm = dp[i][b][c][last];
            if (a > 0 and last != 0) pdm = add(pdm, dp[i+1][b][c][0]);
            if (b > 0 and last != 1) pdm = add(pdm, dp[i+1][b-1][c][1]);
            if (c > 0 and last != 2) pdm = add(pdm, dp[i+1][b][c-1][2]);
            //cerr << b << ' '  << c << ' ' << last << ' ' <<  pdm << endl;
          }
        }

      }
    }
  }

  ll ans[MAX][MAX][MAX];

  auto query = [&] (int a, int b, int c) -> ll {
    ll ret = 0;
    if (a + b + c < tot) return 0;
    if (s[0] == '?') {
      ret = add(ret, dp[1][b][c][0]);
      if (b > 0) ret = add(ret, dp[1][b-1][c][1]);
      if (c > 0) ret = add(ret, dp[1][b][c-1][2]);
    } else {
      if (s[0] == 'a') ret = add(ret, dp[1][b][c][0]);
      if (s[0] == 'b') ret = add(ret, dp[1][b][c][1]);
      if (s[0] == 'c') ret = add(ret, dp[1][b][c][2]);
    }
    return ret;
  };

  ans[1][0][0] = query(1, 0, 0);
  ans[0][1][0] = query(0, 1, 0);
  ans[0][0][1] = query(0, 0, 1);

    for (int a = 0; a <= n; a++) {
      for (int b = 0; b <= n; b++) {
        for (int c = 0; c <= n; c++) {
          auto & pdm = ans[a][b][c];
          pdm = query(a, b, c);
          if (a > 0) pdm = add(pdm, ans[a-1][b][c]);
          if (b > 0) pdm = add(pdm, ans[a][b-1][c]);
          if (c > 0) pdm = add(pdm, ans[a][b][c-1]);


          if (a > 0 and b > 0) pdm -= ans[a-1][b-1][c];
          if (a > 0 and c > 0) pdm -= ans[a-1][b][c-1];
          if (b > 0 and c > 0) pdm -= ans[a][b-1][c-1];


          if (a > 0 and b > 0 and c > 0) pdm = add(pdm, ans[a-1][b-1][c-1]);

        }
      }
    }

  while(q--) {
    int x, y, z; cin >> x >> y >> z;

    cout << ans[x][y][z] << endl;
  }

  return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:44:3: error: ‘memset’ was not declared in this scope
   44 |   memset(dp, 0, sizeof dp);
      |   ^~~~~~
answer.code:4:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    3 | #include <iostream>
  +++ |+#include <cstring>
    4 |