QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#861240 | #9980. Boolean Function Reconstruction | ucup-team5234# | WA | 30ms | 3712kb | C++23 | 2.3kb | 2025-01-18 16:38:18 | 2025-01-18 16:40:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;
void solve() {
int n;
cin >> n;
string s; cin >> s;
bool ng = 0;
rep(bit, 1 << n) {
rep(i, n) {
if(bit >> i & 1) continue;
if(s[bit] == '1' and s[bit | (1 << i)] == '0') ng = 1;
}
}
if(ng) {
cout << "No" << endl;
return ;
}
cout << "Yes" << endl;
if(count(all(s), '0') == 0) {
cout << "T" << endl;
return;
}
if(count(all(s), '1') == 0) {
cout << "F" << endl;
return;
}
vector dp(1 << n, vector(n, 0));
auto dfs = [&](auto dfs, int bits, int i) -> void {
if(i == n - 1) {
if(s[bits | (1 << i)] == s[bits]) dp[bits][i] = 0;
else dp[bits][i] = 1;
return;
}
dfs(dfs, bits | (1 << i), i + 1);
dfs(dfs, bits, i + 1);
if(dp[bits | (1 << i)][i + 1] == 0 and dp[bits][i + 1] == 0) {
if(s[bits] == s[bits | (1 << i)]) {
dp[bits][i] = 0;
return;
}
}
dp[bits][i] = 1;
return;
};
dfs(dfs, 0, 0);
auto dfs1 = [&](auto dfs1, int bits, int i) -> void {
if(!dp[bits][i]) return;
if(i == n - 1) {
cout << char('a' + i);
return;
}
if(dp[bits | (1 << i)][i + 1]) {
if(dp[bits][i + 1]) cout << '(';
cout << '(';
cout << char('a' + i);
cout << '&';
dfs1(dfs1, bits | (1 << i), i + 1);
cout << ')';
} else {
if(dp[bits][i + 1]) cout << '(';
cout << char('a' + i);
}
if(dp[bits][i + 1]) {
cout << '|';
dfs1(dfs1, bits, i + 1);
cout << ')';
}
};
dfs1(dfs1, 0, 0);
cout << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
rep(i, t) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
7 2 0001 2 0111 2 1111 3 00010111 1 10 2 0101 5 00000000000000000000000000000001
output:
Yes (a&b) Yes (a|b) Yes T Yes ((a&(b|c))|(b&c)) No Yes a Yes (a&(b&(c&(d&e))))
result:
ok 7 lines, tightest: 4 out of 14 (7 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3712kb
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: 1ms
memory: 3456kb
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 (a&b) No Yes a No Yes ((a&b)|b) No Yes (a|b) Yes T
result:
ok 16 lines, tightest: 2 out of 12 (16 test cases)
Test #4:
score: 0
Accepted
time: 1ms
memory: 3584kb
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: 6 out of 14 (256 test cases)
Test #5:
score: 0
Accepted
time: 30ms
memory: 3712kb
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: 14 out of 18 (65536 test cases)
Test #6:
score: 0
Accepted
time: 0ms
memory: 3712kb
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 (a&(b&(c&d))) Yes ((a&(b&(c&d)))|(b&(c&d))) Yes (a&((b&(c&d))|(c&d))) Yes ((a&((b&(c&d))|(c&d)))|(b&(c&d))) Yes ((a&((b&(c&d))|(c&d)))|((b&(c&d))|(c&d))) Yes (a&(b&((c&d)|d))) Yes ((a&(b&((c&d)|d)))|(b&(c&d))) Yes (a&((b&((c&d)|d))|(c&d))) Yes ((a&((b&((c&d)|d))|(c&d)))|(b&(c&d))) Yes ((a&...
result:
ok 168 lines, tightest: 14 out of 18 (168 test cases)
Test #7:
score: -100
Wrong Answer
time: 12ms
memory: 3712kb
input:
7581 5 00000000000000000000000000000000 5 00000000000000000000000000000001 5 00000000000000000000000000000011 5 00000000000000000000000000000101 5 00000000000000000000000000000111 5 00000000000000000000000000001111 5 00000000000000000000000000010001 5 00000000000000000000000000010011 5 0000000000000...
output:
Yes F Yes (a&(b&(c&(d&e)))) Yes ((a&(b&(c&(d&e))))|(b&(c&(d&e)))) Yes (a&((b&(c&(d&e)))|(c&(d&e)))) Yes ((a&((b&(c&(d&e)))|(c&(d&e))))|(b&(c&(d&e)))) Yes ((a&((b&(c&(d&e)))|(c&(d&e))))|((b&(c&(d&e)))|(c&(d&e)))) Yes (a&(b&((c&(d&e))|(d&e)))) Yes ((a&(b&((c&(d&e))|(d&e))))|(b&(c&(d&e)))) Yes (a&((b&(...
result:
wrong answer 27 operations, you can't use more than 26 operations (test case 134)