QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875442 | #9980. Boolean Function Reconstruction | ucup-team5008# | WA | 0ms | 3840kb | C++20 | 1.2kb | 2025-01-29 19:43:22 | 2025-01-29 19:43:22 |
Judging History
answer
#include <cstdio>
#include <cassert>
#include <string>
const int N = 1 << 15;
int t, n;
bool ok = 1;
char s[N + 1];
std::string run(int ind = n - 1, int rest = 0) {
if (ind == -1) {
if (s[rest] == '0') return "F";
return "T";
}
bool valuable = 0;
for (int i = 0; i < 1 << ind; ++i) if (s[i | rest] != s[i | rest | 1 << ind]) {
valuable = 1;
if (s[i | rest] == '1') ok = 0;
}
if (!valuable) return run(ind - 1, rest);
//printf("valubale %d\n", ind);
std::string X = run(ind - 1, rest), Y = run(ind - 1, rest | 1 << ind);
if (X == "T") return "T";
if (Y == "F") return X;
if (X == "F") {
if (Y == "T") return std::string() + char('a' + ind);
return '(' + Y + '&' + char('a' + ind) + ')';
}
if (Y == "T") return '(' + X + '|' + char('a' + ind) + ')';
return '(' + X + "|(" + char('a' + ind) + '&' + Y + "))";
}
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
scanf("%s", s);
ok = 1;
auto ans = run();
if (ok) {
printf("Yes\n");
int op = 0;
for (int i = 0; i < ans.size(); ++i) if (ans[i] == '&' || ans[i] == '|') ++op;
assert(op <= (1 << n - 1) + 10);
//printf("%s\n", ans.c_str());
} else printf("No\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3840kb
input:
7 2 0001 2 0111 2 1111 3 00010111 1 10 2 0101 5 00000000000000000000000000000001
output:
Yes Yes Yes Yes No Yes Yes
result:
wrong answer Token parameter [name=expression] equals to "Yes", doesn't correspond to pattern "[a-z()TF&\|]+" (test case 1)