QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#511247#8776. Not Another Constructive!Noobie_99#RE 0ms0kbC++201.7kb2024-08-09 18:00:372024-08-09 18:00:38

Judging History

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

  • [2024-08-09 18:00:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-09 18:00:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define tsolve int t; cin >> t; while(t--) solve
#define debug(x) cerr << __LINE__ << ": "#x" = " << (x) << endl
#define all(x) ::begin(x), ::end(x)
#define sz(x) (int)::size(x)
using ll = long long;
using ld = long double;

constexpr int N1 = 40 + 1;
constexpr int N2 = 20*20 + 1;
constexpr int N3 = 2500 + 1;

bool dp[N1][N2][N3];
bool dp2[N1][N2][N3];

void solve() {
	int n, K;
	cin >> n >> K;
	string s;
	cin >> s;

	char pre[N1][N1][N2][N3];
	dp[0][0][0] = true;

	for (int i=0; i<n; i++) {
		memset(dp2, false, sizeof(dp2));

		int n1 = i;
		int n2 = min(N2-1, (i+1)/2*(i/2));
		int n3 = min(N3-1, (i+2)/3 * (i+2)/3 * (i/3));
		for (int j=0; j<=n1; j++) {
			for (int k=0; k<=n2; k++) {
				for (int l=0; l<=n3; l++) if (dp[j][k][l]) {
					if (s[i] == 'N' || s[i] == '?') {
						pre[i+1][j+1][k][l] = 'N';
						dp2[j+1][k][l] = true;
					}
					if (s[i] == 'A' || s[i] == '?') {
						pre[i+1][j][k+j][l] = 'A';
						dp2[j][k+j][l] = true;
					}
					if (s[i] == 'C' || s[i] == '?') {
						pre[i+1][j][k][l+k] = 'C';
						dp2[j][k][l+k] = true;
					}
					if (s[i] != 'N' && s[i] != 'A' && s[i] != 'C') {
						pre[i+1][j][k][l] = s[i];
						dp2[j][k][l] = true;
					}
				}
			}
		}
		memcpy(dp, dp2, sizeof(dp));
	}

	int x = -1, y = -1, z = -1;
	for (int i=0; i<N1; i++) for (int j=0; j<N2; j++) if (dp[i][j][K]) {
		x = i, y = j, z = K;
	}

	if (x == -1) {
		cout << "-1\n";
		return;
	}

	for (int i=n; i>0; i--) {
		s[i-1] = pre[i][x][y][z];
		if (s[i-1] == 'N') x--;
		else if (s[i-1] == 'A') y -= x;
		else if (s[i-1] == 'C') z -= y;
	}
	cout << s << '\n';
}

int main() {
	cin.tie(0)->sync_with_stdio(false);
	cout << setprecision(16);
	solve();
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

22 2
N??A??????C???????????

output:


result: