QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129331#5250. Combination LocksSommohito#WA 2ms4596kbC++204.2kb2023-07-22 15:30:452023-07-22 15:30:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 15:30:48]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4596kb
  • [2023-07-22 15:30:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define ALL(x) x.begin(),x.end()
const long long flow_inf = 1e18;
const int N=1e4;
struct Blossom {
  int vis[N], par[N], orig[N], match[N], aux[N], t;
  int n;
  bool ad[N];
  vector<int> g[N];
  queue<int> Q;
  Blossom() {}
  Blossom(int _n) {
    n = _n;
    t = 0;
    for (int i = 0; i <= _n; ++i) {
      g[i].clear();
      match[i] = aux[i] = par[i] = vis[i] = aux[i] = ad[i] = orig[i] = 0;
    }
  }
  void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
  }
  void augment(int u, int v) {
    int pv = v, nv;
    do {
      pv = par[v];
      nv = match[pv];
      match[v] = pv;
      match[pv] = v;
      v = nv;
    } while (u != pv);
  }
  int lca(int v, int w) {
    ++t;
    while (true) {
      if (v) {
        if (aux[v] == t) return v;
        aux[v] = t;
        v = orig[par[match[v]]];
      }
      swap(v, w);
    }
  }
  void blossom(int v, int w, int a) {
    while (orig[v] != a) {
      par[v] = w;
      w = match[v];
      ad[v] = true;
      if (vis[w] == 1) Q.push(w), vis[w] = 0;
      orig[v] = orig[w] = a;
      v = par[w];
    }
  }
  //it finds an augmented path starting from u
  bool bfs(int u) {
    fill(vis + 1, vis + n + 1, -1);
    iota(orig + 1, orig + n + 1, 1);
    Q = queue<int> ();
    Q.push(u);
    vis[u] = 0;
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      ad[v] = true;
      for (int x : g[v]) {
        if (vis[x] == -1) {
          par[x] = v;
          vis[x] = 1;
          if (!match[x]) return augment(u, x), true;
          Q.push(match[x]);
          vis[match[x]] = 0;
        } else if (vis[x] == 0 && orig[v] != orig[x]) {
          int a = lca(orig[v], orig[x]);
          blossom(x, v, a);
          blossom(v, x, a);
        }
      }
    }
    return false;
  }
  int maximum_matching() {
    int ans = 0;
    vector<int> p(n - 1);
    iota(p.begin(), p.end(), 1);
//    shuffle(p.begin(), p.end(), rnd);
//    for (int i = 1; i <= n; i++) shuffle(g[i].begin(), g[i].end(), rnd);
    for (auto u : p) {
      if (!match[u]) {
        for(auto v : g[u]) {
          if (!match[v]) {
            match[u] = v, match[v] = u;
            ++ans;
            break;
          }
        }
      }
    }
    for(int i = 1; i <= n; ++i) if (!match[i] && bfs(i)) ++ans;
    return ans;
  }
} dinic1;
int dead[1<<10+5];
int init;
int n,c;
int total;

void ADD(int u,int v)
{
    dinic1.add_edge(u+1,v+1);
}

void dfs(int mask)
{
    dead[mask]=2;
    int cnt=__builtin_popcount(mask);

    for(int i=0;i<n;i++)
    {
        int notun=mask^(1<<i);
        if(dead[notun]==1||dead[notun]==2)
            continue;
        if(cnt%2==__builtin_popcount(init)%2)
            ADD(mask,notun);
        else ADD(notun,mask);

        dfs(notun);
    }

}

void TEST_CASES()
{
    cin>>n>>c;
    string a,b;
    cin>>a>>b;
    init=0,total=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
            init|=(1<<i);
    }
    memset(dead,0,sizeof dead);
    dinic1=Blossom((1<<n)+5);
    for(int i=0;i<c;i++)
    {
        string a;
        cin>>a;
        int here=0;
        for(int j=0;j<n;j++)
        {
            if(a[j]=='.')
                here|=(1<<j);
        }
        dead[here]=1;
    }
    dfs(init);
//    debug(total);
    int ans=dinic1.maximum_matching();
    if (ans * 2 == total) cout << "Alice" << '\n';
    else {
      memset(dinic1.ad, 0, sizeof dinic1.ad);
      for (int i = 1; i <= (1<<n)+5; i++) if (dinic1.match[i] == 0) dinic1.bfs(i);
      int ans = 0;
      if(dinic1.ad[init+1])
        cout<<"Bob\n";
      else cout<<"Alice\n";
    }
}


/*
3
2 2
12
89
=.
==
3 1
204
101
.==
3 2
000
000
...
==.
*/

int32_t main()
{
#ifndef APURBA
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    //freopen("input.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int t=1;
    cin>>t;
    while(t--)
    {
        TEST_CASES();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4596kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Alice

result:

wrong answer 2nd lines differ - expected: 'Bob', found: 'Alice'