QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89545 | #5250. Combination Locks | molarsu | WA | 2ms | 3472kb | C++20 | 3.5kb | 2023-03-20 15:42:59 | 2023-03-20 15:43:01 |
Judging History
answer
#include<bits/stdc++.h>
#define ri register int
#define fu(i, a, b) for(ri i = (a), ed = (b); i <= ed; ++i)
#define fd(i, a, b) for(ri i = (a), ed = (b); i >= ed; --i)
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = (1 << 10) + 5;
const int M = N * 10;
int read(){
int f = 1, x = 0; char ch = getchar();
while(ch > '9' || ch < '0'){ if(ch == '-')f = -1; ch = getchar(); }
while(ch <= '9' && ch >= '0'){ x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
return x * f;
}
int S, T, n, m, tot;
int dis[N], in[N], out[N], L[N], R[N];
int ecnt = 1, head[N], cur[N];
bool vis[N];
struct Edge {
int v, flow, nxt;
}e[M];
void init_edge() {
memset(head, -1, (tot + 2) * sizeof head[0]);
ecnt = 1;
}
int pop_count(int x){
int res = 0;
while(x){
if(x & 1)res++;
x >>= 1;
}
return res;
}
void add_edge(int u, int v, int flow) {
ecnt++;
e[ecnt] = {v, flow, head[u]};
head[u] = ecnt;
//cout << ecnt << " " << u << " " << v << " " << flow << endl;
}
void add2(int u, int v, int flow){
add_edge(u, v, flow);
add_edge(v, u, 0);
}
bool dinic_bfs(int s) {
memset(dis, -1, (tot + 2) * sizeof(dis[0]));
dis[s] = 0;
queue<int> que;
que.push(s);
while (!que.empty()) {
int u = que.front(); que.pop();
for (int i = head[u]; i != -1; i = e[i].nxt) {
int v = e[i].v;
if (dis[v] == -1 && e[i].flow) {
dis[v] = dis[u] + 1;
que.push(v);
}
}
}
//for (int i = 1; i <= n; i++)cout << dis[i] << endl;
return dis[T] != -1;
}
int dinic_dfs(int u, int flow) {
if (u == T) { return flow; }
int delta = flow;
for (int i = cur[u]; i != -1; i = e[i].nxt) {
cur[u] = i;
int v = e[i].v;
if (dis[v] == dis[u] + 1 && e[i].flow) {
int d = dinic_dfs(v, min(delta, e[i].flow));
e[i].flow -= d, e[i ^ 1].flow += d;
delta -= d;
if (delta == 0)break;
}
}
if (delta == flow)dis[u] = -1;
return flow - delta;
}
int dinic() {
int ans = 0;
while (dinic_bfs(S)) {
memcpy(cur, head, sizeof head);
ans += dinic_dfs(S, INF);
}
return ans;
}
signed main(){
//n = read(), m = read(), tot = n, S = read(), T = read();
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;cin >> t;
while(t--){
int len, num;
string s1, s2;
memset(vis, 0, sizeof vis);
cin >> len >> num;
tot = (1 << len) + 3;
init_edge();
cin >> s1 >> s2;
S = (1 << len) + 1, T = (1 << len) + 2;
int p0 = 0;
fu(i, 0, len - 1) {
p0 <<= 1;
if(s1[i] == s2[i]) p0++;
}
fu(i, 1, num) {
string s;
cin >> s;
int p = 0;
fu(j, 0, len - 1){
p <<= 1;
if(s[j] == '=')p++;
}
vis[p] = 1;
}
fu(i, 0, (1 << len) - 1) {
if(vis[i] || i == p0) continue;
bool f1 = 0;
if(pop_count(i) & 1) f1 = 1, add2(S, i, 1);
else add2(i, T, 1);
fu(j, i + 1, (1 << len) - 1){
if(vis[j] || j == p0) continue;
int x = j - i;
if((x & (x - 1)) == 0)
if(f1)add2(i, j, 1);
else add2(j, i, 1);
}
}
int res1 = dinic();
fu(i, 0, (1 << len) - 1) {
if(vis[i]) continue;
bool f1 = 0;
if(pop_count(i) & 1) f1 = 1, add2(S, i, 1);
else add2(i, T, 1);
fu(j, i + 1, (1 << len) - 1){
if(vis[j]) continue;
int x = j - i;
if((x & (x - 1)) == 0)
if(f1)add2(i, j, 1);
else add2(j, i, 1);
}
}
int res2 = dinic();
//cout << res1 << " " << res2 << "\n";
if(res2 > res1) cout << "Alice\n";
else cout << "Bob\n";
}
init_edge();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3324kb
input:
2 1 0 0 0 1 1 0 0 .
output:
Alice Bob
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
8 2 0 00 00 2 1 00 00 .. 2 1 00 00 =. 2 2 00 00 .. =. 2 1 00 00 .= 2 2 00 00 .. .= 2 2 00 00 =. .= 2 3 00 00 .. =. .=
output:
Alice Alice Bob Alice Bob Alice Bob Bob
result:
ok 8 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 3328kb
input:
20 4 4 4714 5245 ..=. ..== .==. ==.. 4 1 2697 1438 .=.. 4 5 9255 0677 ...= ..== =..= ==.= ==== 4 12 3292 7326 ...= ..=. ..== .=.. .=.= .==. =... =..= =.== ==.. ==.= ==== 4 9 8455 2536 ...= ..== .=.. .=.= .==. .=== =... ==.. ===. 4 12 5755 1517 ...= ..=. ..== .=.. .=.= .=== =..= =.=. =.== ==.. ==.= =...
output:
Alice Bob Alice Bob Bob Alice Bob Bob Alice Alice Bob Alice Alice Bob Bob Bob Bob Bob Bob Bob
result:
ok 20 lines
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 3472kb
input:
20 5 30 99942 90170 ..... ....= ...== ..=.. ..=.= ..==. ..=== .=... .=..= .=.=. .=.== .==.. .==.= .===. .==== =...= =..=. =..== =.=.. =.=.= =.==. =.=== ==... ==..= ==.=. ==.== ===.. ===.= ====. ===== 5 14 11760 95480 ...=. ...== ..=.. ..=.= .=... .=..= .==== =.... =...= =.=.. =.==. ==... ==.== =====...
output:
Bob Alice Alice Alice Alice Bob Bob Bob Alice Alice Alice Bob Alice Bob Alice Alice Alice Alice Alice Bob
result:
wrong answer 14th lines differ - expected: 'Alice', found: 'Bob'