QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#861485 | #9980. Boolean Function Reconstruction | ucup-team3802# | WA | 197ms | 4736kb | C++20 | 2.5kb | 2025-01-18 17:39:20 | 2025-01-18 17:39:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, l, r) for(ll i = l; i < r; i++)
#define all(ar) begin(ar), end(ar)
const ll a[5] = {
0b00000000000000001111111111111111, 0b00000000111111110000000011111111,
0b00001111000011110000111100001111, 0b00110011001100110011001100110011,
0b01010101010101010101010101010101};
unordered_map<ll, string> st;
vector<vector<ll>> mask(14);
bool built = false;
void sol(int n, char top) {
int sz = 1 << n;
rep(i, 5 - n, 5) {
mask[1].push_back(a[i]);
st[a[i]] = top;
top++;
}
st[0b11111111111111111111111111111111] = "T";
st[0] = "F";
rep(i, 2, 14) {
rep(j, 1, i) {
int k = i - j;
if(j > k) break;
for(ll x : mask[j])
for(ll y : mask[k]) {
if(!st.count(x | y)) {
st[x | y] = "(" + st[x] + "|" + st[y] + ")";
mask[i].push_back(x | y);
}
if(!st.count(x & y)) {
st[x & y] = "(" + st[x] + "&" + st[y] + ")";
mask[i].push_back(x & y);
}
}
}
}
built = true;
}
bool f(int n, string s, char c, string &ans) {
if(n >= 6) {
int sz = s.size();
int half = sz / 2;
rep(i, 0, half) if(s[i] == '1' && s[half + i] == '0') return true;
ans += "(";
bool l = f(n - 1, s.substr(0, half), c + 1, ans);
if(l) return true;
ans += ")|(";
ans += c;
ans += "&(";
bool r = f(n - 1, s.substr(half), c + 1, ans);
if(r) return true;
ans += "))";
return false;
} else {
while(s.size() < 32u) s += s;
ll x = stoll(s, nullptr, 2);
if(!st.count(x)) return true;
ans += st[x];
return false;
}
}
void solve() {
int n;
cin >> n;
string s;
cin >> s;
string ans;
if(f(n, s, 'a', ans)) {
cout << "No" << endl;
return;
}
for(char &c : ans) {
if(isdigit(c)) {
c -= '0';
c += 'a';
c += n - 5;
}
}
for(char &c : ans) {
if('a' <= c && c <= 'z') {
c = 'a' + 'a' + n - 1 - c;
}
}
cout << "Yes" << endl;
cout << ans << endl;
}
int main() {
sol(5, '0');
int t = 1;
cin >> t;
while(t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 145ms
memory: 4736kb
input:
7 2 0001 2 0111 2 1111 3 00010111 1 10 2 0101 5 00000000000000000000000000000001
output:
Yes (b&a) Yes (b|a) Yes T Yes ((c|b)&(a|(c&b))) No Yes a Yes (e&(d&(c&(b&a))))
result:
ok 7 lines, tightest: 4 out of 14 (7 test cases)
Test #2:
score: 0
Accepted
time: 146ms
memory: 4608kb
input:
4 1 00 1 10 1 01 1 11
output:
Yes F No Yes a Yes T
result:
ok 4 lines, tightest: 0 out of 11 (4 test cases)
Test #3:
score: 0
Accepted
time: 144ms
memory: 4736kb
input:
16 2 0000 2 1000 2 0100 2 1100 2 0010 2 1010 2 0110 2 1110 2 0001 2 1001 2 0101 2 1101 2 0011 2 1011 2 0111 2 1111
output:
Yes F No No No No No No No Yes (b&a) No Yes a No Yes b No Yes (b|a) Yes T
result:
ok 16 lines, tightest: 1 out of 12 (16 test cases)
Test #4:
score: 0
Accepted
time: 145ms
memory: 4736kb
input:
256 3 00000000 3 10000000 3 01000000 3 11000000 3 00100000 3 10100000 3 01100000 3 11100000 3 00010000 3 10010000 3 01010000 3 11010000 3 00110000 3 10110000 3 01110000 3 11110000 3 00001000 3 10001000 3 01001000 3 11001000 3 00101000 3 10101000 3 01101000 3 11101000 3 00011000 3 10011000 3 01011000...
output:
Yes F No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 256 lines, tightest: 4 out of 14 (256 test cases)
Test #5:
score: 0
Accepted
time: 197ms
memory: 4736kb
input:
65536 4 0000000000000000 4 1000000000000000 4 0100000000000000 4 1100000000000000 4 0010000000000000 4 1010000000000000 4 0110000000000000 4 1110000000000000 4 0001000000000000 4 1001000000000000 4 0101000000000000 4 1101000000000000 4 0011000000000000 4 1011000000000000 4 0111000000000000 4 1111000...
output:
Yes F No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No ...
result:
ok 65536 lines, tightest: 7 out of 18 (65536 test cases)
Test #6:
score: 0
Accepted
time: 147ms
memory: 4608kb
input:
168 4 0000000000000000 4 0000000000000001 4 0000000000000011 4 0000000000000101 4 0000000000000111 4 0000000000001111 4 0000000000010001 4 0000000000010011 4 0000000000010101 4 0000000000010111 4 0000000000011111 4 0000000000110011 4 0000000000110111 4 0000000000111111 4 0000000001010101 4 000000000...
output:
Yes F Yes (d&(c&(b&a))) Yes (d&(c&b)) Yes (d&(c&a)) Yes (d&(c&(b|a))) Yes (d&c) Yes (d&(b&a)) Yes (d&(b&(c|a))) Yes (d&(a&(c|b))) Yes (d&((c|b)&(a|(c&b)))) Yes (d&(c|(b&a))) Yes (d&b) Yes (d&(b|(c&a))) Yes (d&(c|b)) Yes (d&a) Yes (d&(a|(c&b))) Yes (d&(c|a)) Yes (d&(b|a)) Yes (d&(c|(b|a))) Yes d Yes ...
result:
ok 168 lines, tightest: 7 out of 18 (168 test cases)
Test #7:
score: -100
Wrong Answer
time: 155ms
memory: 4736kb
input:
7581 5 00000000000000000000000000000000 5 00000000000000000000000000000001 5 00000000000000000000000000000011 5 00000000000000000000000000000101 5 00000000000000000000000000000111 5 00000000000000000000000000001111 5 00000000000000000000000000010001 5 00000000000000000000000000010011 5 0000000000000...
output:
Yes F Yes (e&(d&(c&(b&a)))) Yes (e&(d&(c&b))) Yes (e&(d&(c&a))) Yes (e&(d&(c&(b|a)))) Yes (e&(d&c)) Yes (e&(d&(b&a))) Yes (e&(d&(b&(c|a)))) Yes (e&(d&(a&(c|b)))) Yes (e&(d&((c|b)&(a|(c&b))))) Yes (e&(d&(c|(b&a)))) Yes (e&(d&b)) Yes (e&(d&(b|(c&a)))) Yes (e&(d&(c|b))) Yes (e&(d&a)) Yes (e&(d&(a|(c&b)...
result:
wrong answer Judge finds an answer but participant doesn't (test case 3081)