QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139354#5250. Combination LocksUNos_mariconesWA 1ms3572kbC++203.5kb2023-08-13 02:28:262023-08-13 02:28:27

Judging History

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

  • [2023-08-13 02:28:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3572kb
  • [2023-08-13 02:28:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std ;

#define ff    first
#define ss    second
#define pb    push_back

typedef long long    ll;
typedef pair<ll,ll>    ii;
typedef long double    lf;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll SQ = 800;
const ll N = 3e5+5;
const ll mod = 1e9+7;
const ll oo = 1e18;

/// Complexity: O(|E|*|V|^2)
/// Tested: https://tinyurl.com/ya9rgoyk
struct edge { int v, cap, inv, flow; };
struct network {
  int n, s, t;
  vector<int> lvl;
  vector<vector<edge>> g;
  network(int n) : n(n), lvl(n), g(n) {}
  void add_edge(int u, int v, int c) {
//    cout << u << ' ' << v << ' ' << c << '\n';
    g[u].push_back({v, c, g[v].size(), 0});
    g[v].push_back({u, 0, g[u].size()-1, c});
  }
  bool bfs() {
    fill(lvl.begin(), lvl.end(), -1);
    queue<int> q;
    lvl[s] = 0;
    for(q.push(s); q.size(); q.pop()) {
      int u = q.front();
      for(auto &e : g[u]) {
        if(e.cap > 0 && lvl[e.v] == -1) {
          lvl[e.v] = lvl[u]+1;
          q.push(e.v);
        }
      }
    }
    return lvl[t] != -1;
  }
  int dfs(int u, int nf) {
    if(u == t) return nf;
    int res = 0;
    for(auto &e : g[u]) {
      if(e.cap > 0 && lvl[e.v] == lvl[u]+1) {
        int tf = dfs(e.v, min(nf, e.cap));
        res += tf; nf -= tf; e.cap -= tf;
        g[e.v][e.inv].cap += tf;
        g[e.v][e.inv].flow -= tf;
        e.flow += tf;
        if(nf == 0) return res;
      }
    }
    if(!res) lvl[u] = -1;
    return res;
  }
  int max_flow(int so, int si, int res = 0) {
    s = so; t = si;
    while(bfs()) res += dfs(s, INT_MAX);
    return res;
  }
};

int main(){
  #ifdef LOCAL
  freopen("input.txt","r",stdin);
  #endif // LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);

  int t; cin >> t;
  while (t--) {

    int n, c; cin >> n >> c;
    string s1, s2; cin >> s1 >> s2;
    int s = 0;
    for (int i = 0; i < n; ++i) {
      if (s1[i] == s2[i]) s ^= (1<<i);
    }

    vector <int> forb((1<<n));
    for (int i = 0; i < c; ++i) {
      string x; cin >> x;
      int rx = 0;
      for (int j = 0; j < n; ++j) {
        if (x[j] == '=') rx ^= (1<<j);
      }
      forb[rx] = 1;
    }

    int oness = __builtin_popcount(s);

    network net(2 + (1<<n));
    for (int i = 0; i < (1<<n); ++i) {
      int onesi = __builtin_popcount(i);
      if (onesi % 2 == oness % 2) {
        net.add_edge(0, i + 1, 1);
        for (int j = 0; j < n; ++j) {
          int cn = i ^ (1<<j);
          if (!forb[i] && !forb[cn]) {
            net.add_edge(i + 1, cn + 1, 1);
          }
        }
      }
      else net.add_edge(i + 1, 1 + (1<<n), 1);

    }

    net.max_flow(0, 1 + (1<<n));
    queue <int> q;
    q.push(s + 1);
    vector <int> visi(2 + (1<<n));
    visi[s + 1]=1;
//    oness = __builtin_popcount(s+1);
    while (q.size()) {
      int curr = q.front(); q.pop();
      for (auto &e : net.g[curr]) {
        if (e.v == 0 || e.v == 1 + (1<<n)) continue;
        int onesv = __builtin_popcount(e.v-1);
        if (((onesv % 2 == oness % 2 && e.cap == 0) || (onesv % 2 != oness % 2 && e.cap==1)) && !visi[e.v]) {
          q.push(e.v);
          visi[e.v]=1;
        }
      }
    }
    int can = 1;
    for (auto &e : net.g[0]) {
//      cout << e.v << ' ' << e.cap << ' ' << visi[e.v] << '\n';
      if (e.cap && visi[e.v])
        can=0;
    }
    if (can) cout << "Alice\n";
    else cout << "Bob\n";
  }

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 3572kb

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: -100
Wrong Answer
time: 0ms
memory: 3536kb

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
Alice
Alice
Bob
Bob
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Alice
Bob
Alice
Bob

result:

wrong answer 5th lines differ - expected: 'Bob', found: 'Alice'