QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188191 | #4913. 子集匹配 | hos_lyric# | 40 | 155ms | 13792kb | C++14 | 2.5kb | 2023-09-25 16:29:55 | 2024-07-04 02:08:56 |
Judging History
answer
#include "hall.h"
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
constexpr int MAX_N = 19;
constexpr int MAX_V = 92378;
int N, K;
int to[1 << MAX_N], fr[1 << MAX_N];
int tof, used[1 << MAX_N], lev[1 << MAX_N], que[MAX_V], *qb, *qe;
int augment(int u) {
used[u] = tof;
for (int e = 0; e < N; ++e) if (u & 1 << e) {
const int v = u - (1 << e);
const int w = fr[v];
if (!~w || (used[w] != tof && lev[u] < lev[w] && augment(w))) {
to[u] = v; fr[v] = u; return 1;
}
}
return 0;
}
int run() {
memset(to, ~0, sizeof(to));
memset(fr, ~0, sizeof(fr));
memset(used, ~0, sizeof(used));
for (tof = 0; ; ) {
qb = qe = que; memset(lev, ~0, sizeof(lev));
for (int u = 0; u < 1 << N; ++u) if (__builtin_popcount(u) == K) {
if (!~to[u]) lev[*qe++ = u] = 0;
}
for (; qb != qe; ) {
const int u = *qb++;
for (int e = 0; e < N; ++e) if (u & 1 << e) {
const int w = fr[u - (1 << e)];
if (~w && !~lev[w]) lev[*qe++ = w] = lev[u] + 1;
}
}
int f = 0;
for (int u = 0; u < 1 << N; ++u) if (__builtin_popcount(u) == K) {
if (!~to[u]) f += augment(u);
}
if (!f) return tof;
tof += f;
}
}
int solve(int N_, int K_, int S) {
if (!tof) {
N = N_;
K = K_;
run();
cerr<<"tof = "<<tof<<endl;
}
return to[S];
}
详细
Test #1:
score: 5
Accepted
time: 3ms
memory: 12776kb
input:
14 8
output:
OK
result:
ok "OK"
Test #2:
score: 5
Accepted
time: 7ms
memory: 13364kb
input:
15 8
output:
OK
result:
ok "OK"
Test #3:
score: 5
Accepted
time: 2ms
memory: 12492kb
input:
15 9
output:
OK
result:
ok "OK"
Test #4:
score: 5
Accepted
time: 7ms
memory: 13168kb
input:
15 10
output:
OK
result:
ok "OK"
Test #5:
score: 5
Accepted
time: 53ms
memory: 12580kb
input:
18 10
output:
OK
result:
ok "OK"
Test #6:
score: 5
Accepted
time: 155ms
memory: 13312kb
input:
19 10
output:
OK
result:
ok "OK"
Test #7:
score: 5
Accepted
time: 90ms
memory: 13792kb
input:
19 11
output:
OK
result:
ok "OK"
Test #8:
score: 5
Accepted
time: 64ms
memory: 13760kb
input:
19 12
output:
OK
result:
ok "OK"
Test #9:
score: 0
Runtime Error
input:
22 12
output:
result:
Test #10:
score: 0
Runtime Error
input:
23 12
output:
result:
Test #11:
score: 0
Runtime Error
input:
23 13
output:
result:
Test #12:
score: 0
Runtime Error
input:
23 14
output:
result:
Test #13:
score: 0
Runtime Error
input:
24 13
output:
result:
Test #14:
score: 0
Runtime Error
input:
25 13
output:
result:
Test #15:
score: 0
Runtime Error
input:
25 14
output:
result:
Test #16:
score: 0
Runtime Error
input:
25 15
output:
result:
Test #17:
score: 0
Runtime Error
input:
26 14
output:
result:
Test #18:
score: 0
Runtime Error
input:
27 14
output:
result:
Test #19:
score: 0
Runtime Error
input:
27 15
output:
result:
Test #20:
score: 0
Runtime Error
input:
27 16