QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875553#9544. Grand Prix of Ballancewarner1129#RE 0ms0kbC++203.0kb2025-01-29 23:07:382025-01-29 23:07:38

Judging History

This is the latest submission verdict.

  • [2025-01-29 23:07:38]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-29 23:07:38]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

template<class F, class S>
ostream &operator<<(ostream &s, const pair<F, S> &v) {
	s << "(" << v.first << ", " << v.second << ")";
	return s;
}
template<ranges::range T> requires (!is_convertible_v<T, string_view>)
istream &operator>>(istream &s, T &&v) { 
	for (auto &&x : v) s >> x; 
	return s; 
}
template<ranges::range T> requires (!is_convertible_v<T, string_view>)
ostream &operator<<(ostream &s, T &&v) { 
	for (auto &&x : v) s << x << ' '; 
	return s; 
}

#ifdef LOCAL
template<class... T> void dbg(T... x) {
	char e{};
	((cerr << e << x, e = ' '), ...);
}
#define debug(x...) dbg(#x, '=', x, '\n')
#else
#define debug(...) ((void)0)
#endif

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second

template<class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
bool chmin(auto &a, auto b) { return (b < a and (a = b, true)); }
bool chmax(auto &a, auto b) { return (a < b and (a = b, true)); }

using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;

constexpr i64 mod = 1E9 + 7;

void solve() {
	int n, q;
	cin >> n >> q;

	string s;
	cin >> s;

	vector dp(3, vector(n + 1, vector<i64>(n + 1)));

	for (int i = 0; i < 3; i++) {
		if (s[0] == '?' or i == s[0] - 'a') {
			dp[i][i == 0][i == 1] = 1;
		}
	}

	for (int i = 1; i < n; i++) {
		vector ndp(3, vector(n + 1, vector<i64>(n + 1)));
		for (int a : {0, 1, 2})
		for (int b : {0, 1, 2}) {
			if (a == b) {
				continue;
			}
			if (s[i] == '?' or s[i] - 'a' == b) {
				for (int x = 0; x <= i; x++)
					for (int y = 0; y <= i; y++) {
						(ndp[b][x + (b == 0)][y + (b == 1)] += dp[a][x][y]) %= mod;
					}
			}
		}
		dp = ndp;
	}

	const int A = ranges::count(s, 'a');
	const int B = ranges::count(s, 'b');
	const int C = ranges::count(s, 'c');
	const int Q = ranges::count(s, '?');

	vector sum(n + 1, vector(n + 1, vector<i64>(n + 1)));
	for (int a = 0; a <= n; a++)
		for (int b = 0; b <= n; b++) {
			i64 t = (dp[0][a][b] + dp[1][a][b] + dp[2][a][b]) % mod;
			if (t) {
				int c = n - a - b - C;
				sum[a - A][b - B][c] = t;
			}
		}

	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
			for (int k = 1; k <= n; k++) {
				sum[i][j][k] += sum[i][j][k - 1];
				sum[i][j][k] %= mod;
			}
	for (int i = 0; i <= n; i++)
		for (int j = 1; j <= n; j++)
			for (int k = 0; k <= n; k++) {
				sum[i][j][k] += sum[i][j - 1][k];
				sum[i][j][k] %= mod;
			}
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n; j++)
			for (int k = 0; k <= n; k++) {
				sum[i][j][k] += sum[i - 1][j][k];
				sum[i][j][k] %= mod;
			}

	while (q--) {
		int a, b, c;
		cin >> a >> b >> c;

		cout << sum[a][b][c] << '\n';
	}
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int t = 1;
	// cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

3
3 4 6
1 2
2 1 1
2 2 2
3 3 2
2 3 2
2 1 2
3 4 8
1 2
2 1 1
2 2 2
3 3 2
2 3 2
2 1 2
1 1
2 1 1
3 4 7
1 2
2 1 1
2 2 2
3 3 2
2 3 2
2 1 2
1 1

output:


result: