QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648827#9463. 基础 ABC 练习题hos_lyric0 0ms0kbC++142.8kb2024-10-17 20:33:502024-10-17 20:33:57

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 20:33:57]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-17 20:33:50]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


int subtaskId;
int N;
char A[210], B[210], S[210];

unsigned dp[62][62][62];

unsigned solve(int x, int y, int z) {
  if (!(x >= 0 && y >= 0 && z >= 0)) return 0;
  for (int a = 0; a <= N; ++a) for (int b = 0; b <= N; ++b) for (int c = 0; c <= N; ++c) dp[a][b][c] = 0;
  dp[0][0][0] = 1;
  for (int a = 0; a <= N; ++a) for (int b = 0; b <= N; ++b) for (int c = 0; c <= N; ++c) if (dp[a][b][c]) {
    if (a-c <= x && b-a <= y && c-b <= z) {
      const int i = a + b + c;
      if (S[i] == '?' || S[i] == 'A') dp[a + 1][b][c] += dp[a][b][c];
      if (S[i] == '?' || S[i] == 'B') dp[a][b + 1][c] += dp[a][b][c];
      if (S[i] == '?' || S[i] == 'C') dp[a][b][c + 1] += dp[a][b][c];
    }
  }
  return dp[N][N][N];
}

int main() {
  for (int numCases; ~scanf("%d%d", &numCases, &subtaskId); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d", &N);
    scanf("%s", A);
    scanf("%s", B);
    scanf("%s", S);
    
    vector<int> xs(N + 1, N + 1), ys(N + 1, N + 1);
    for (int x = N; x >= 0; --x) xs[x] = (A[x] == '1') ? x : xs[x + 1];
    for (int y = N; y >= 0; --y) ys[y] = (B[y] == '1') ? y : ys[y + 1];
    
    unsigned ans = 0;
    for (int x = 0; x <= N; ++x) for (int y = 0; x + y <= N; ++y) {
      if (xs[x] <= N && ys[y] <= N) {
        const int z = N - xs[x] - ys[y];
        unsigned here = 0;
        here += solve(x, y, z);
        here -= solve(x, y - 1, z);
        here -= solve(x - 1, y, z);
        here += solve(x - 1, y - 1, z);
        ans += here;
      }
    }
    printf("%u\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

60 1
1
11
11
ABC
2
111
111
CABABC
3
1111
1111
CAABBCBAC
4
11111
11111
BACBBACBACAC
5
111111
111111
CABCCBBAABCCBAA
6
1111111
1111111
ABABABCACBCBCCACBA
7
11111111
11111111
BCAABACBBCBBABCCAACAC
8
111111111
111111111
CCBCBBBCAABCBCAAAAACBCBA
9
1111111111
1111111111
CCCCACABCBABAABCCAABABBCBBA
10
1111...

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

input:

60 3
1
11
11
???
2
111
111
??????
3
1111
1111
?????????
4
11111
11111
????????????
5
111111
111111
???????????????
6
1111111
1111111
??????????????????
7
11111111
11111111
?????????????????????
8
111111111
111111111
????????????????????????
9
1111111111
1111111111
???????????????????????????
10
1111...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%