namespace G1 { std::bitset<51> vis; int head[51], dis[51]; Edge e[2451];
inlinevoidaddEdge(int u, int v, int w);
voidspfa(int s); } // G1
namespace G2 { int *h = G1::dis, head[51]; Edge e[2451];
structNode { std::bitset<51> vis; int s, u, len, f; std::vector<int> z;
booloperator<(const Node &rhs) const { if (f != rhs.f) return f > rhs.f; for (int i = 0, mx = std::min(z.size(), rhs.z.size()); i < mx; ++i) if (z[i] != rhs.z[i]) return z[i] > rhs.z[i]; return z.size() > rhs.z.size(); } };
inlinevoidaddEdge(int u, int v, int w);
voidAstar(int s, int t){ std::priority_queue<Node> q; q.push({std::bitset<51>(1ll << s), s, s, 0, h[s], std::vector<int>()}); int cnt = 0; for (Node now, nxt; q.size(); ) { now = q.top(), q.pop(); if (now.u == t && ++cnt == K) { cout << now.s; for (int u : now.z) cout << -u; cout.flush(); exit(0); } for (int i = head[now.u], v; i; i = e[i].nxt) { if (now.vis[v = e[i].to]) continue; nxt = {now.vis, now.s, v, now.len + e[i].w, h[v], now.z}; nxt.vis.set(v), nxt.z.push_back(v), nxt.f += nxt.len; q.push(nxt); } } } } // G2
intmain(){ int M, S, T;
cin >> N >> M >> K >> S >> T; for (int u, v, w; M; --M) { cin >> u >> v >> w; G1::addEdge(v, u, w), G2::addEdge(u, v, w); } G1::spfa(T), G2::Astar(S, T); puts("No"); return0; }
voidinsert(int c, const Data &v){ // v 中的元素为颜色 c 某种状态占据的坐标 staticint M = 0; DLX::link(++M, c); for (constauto &x : v) DLX::link(M, 12 + pos(x.first, x.second)); }
inlineboolvalid(int x, int y){ return1 <= x && x <= 10 && 1 <= y && y <= x && z[x][y] == '.'; }
intmain(){ for (int i = 1; i <= 10; ++i) for (int j = 1; j <= i; ++j) { std::cin >> z[i][j]; if (z[i][j] != '.') { used.set(z[i][j] & 31); v[z[i][j] & 31].push_back({i, j}); } }
DLX::init(67); for (int i = 1; i <= 12; ++i) { if (used[i]) { insert(i, v[i]); continue; } v[i].resize(siz[i]); for (int pi = 1; pi <= 10; ++pi) for (int pj = 1; pj <= pi; ++pj) for (int S = 0; S < 8; ++S) { bool g = 0; for (int j = 0, nx, ny; j < siz[i]; ++j) { nx = sh[i][j][0], ny = sh[i][j][1]; if (S & 4) std::swap(nx, ny); if (S & 2) nx = -nx; if (S & 1) ny = -ny; nx += pi, ny += pj; if (!valid(nx, ny)) { g = 1; break; } v[i][j] = {nx, ny}; } if (!g) insert(i, v[i]); } }
structHash { std::bitset<Hmod> vis; int tv[Hmod], tp[Hmod];
voidclear(){ vis.reset(); }
voidinsert(int p, int v){ int k = p % Hmod; for (; vis[k]; ++k %= Hmod) if (tp[k] == p) { tv[k] = v; return; } vis.set(k), tv[k] = v, tp[k] = p; }
intquery(int p){ for (int k = p % Hmod; vis[k]; ++k %= Hmod) if (tp[k] == p) return tv[k]; return-1; } } z;
intBSGS(int a, int b, int p, int sd){ z.clear(); int v = 1, t = ceil(sqrt(p));
for (int i = 0; i < t; ++i, v = 1ll * v * a % p) z.insert(1ll * v * b % p, i); for (int i = 0, j, v_ = v, v = sd; i <= t; ++i, v = 1ll * v * v_ % p) if ((j = z.query(v)) != -1 && i * t >= j) return i * t - j; return-1; }
intexBSGS(int a, int b, int p){ a %= p, b %= p; if (b == 1 || p == 1) return0; int cnt = 0, sd = 1; for (int d; (d = std::__gcd(a, p)) != 1; ) { if (b % d) return-1; ++cnt, b /= d, p /= d; sd = 1ll * sd * a / d % p; if (sd == b) return cnt; } int ans = BSGS(a, b, p, sd); if (ans != -1) ans += cnt; return ans; }
std::bitset<10000003> v; int p[664581], mu[10000003], g[10000003];
voidsieve(int N){ /* 筛出 mu[1..N] */ for (int i = 1; i <= N; ++i) g[i] = (g[i - 1] + 1ll * i * i % mod * (mu[i] + mod) % mod) % mod; }
intf(int N, int M){ return (1ll * N * (N + 1) / 2 % mod) * (1ll * M * (M + 1) / 2 % mod) % mod; }
intS(int N, int M){ assert(N <= M); int ans = 0; for (int l = 1, r, n, m; l <= N; l = r + 1) { n = N / l, m = M / l; r = std::min(N / n, M / m); ans = (ans + 1ll * (g[r] - g[l - 1] + mod) * f(n, m) % mod) % mod; } return ans; }
intsolve(int N, int M){ assert(N <= M); int ans = 0; for (int l = 1, r, n, m; l <= N; l = r + 1) { n = N / l, m = M / l; r = std::min(N / n, M / m); ans = (ans + 1ll * (r - l + 1) * (l + r) / 2 % mod * S(n, m) % mod) % mod; } return ans; }
intmain(){ int N, M;
std::cin >> N >> M; if (N > M) std::swap(N, M); sieve(N); std::cout << solve(N, M); return0; }
intsolve(int N, int *a, int M, int *b){ int lim, l, ans = 0x3f3f3f3f, ans1 = 0, ans2 = 0, ans3 = 0;
for (lim = 1, l = -1; lim <= N * 3; lim <<= 1, ++l); for (int i = 0; i < lim; ++i) to[i] = (to[i >> 1] >> 1) | ((i & 1) << l);
for (int i = 0, t; i < N; ++i) { t = a[i + 1]; A[N - i].x = A[(N << 1) - i].x = t; ans1 += t * t, ans2 += t << 1; } for (int i = 1, t; i <= N; ++i) { t = b[i]; B[i].x = t; ans1 += t * t, ans2 -= t << 1; }
FFT(lim, A, 1), FFT(lim, B, 1); for (int i = 0; i < lim; ++i) A[i] = A[i] * B[i]; FFT(lim, A, -1); for (int i = N + 1; i <= N << 1; ++i) ans3 = std::max(ans3, int(A[i].x + 0.5)); for (int i = -M; i <= M; ++i) ans = std::min(ans, i * ans2 + N * i * i); ans += ans1 - (ans3 << 1); printf("%d\n", ans); return0; }
voiddfs(int u){ vis.set(u); f[u][u >> 5] |= 1 << (u & 31); for (int v : D[u]) if (!(f[u][v >> 5] & (1 << (v & 31)))) { if (!vis[v]) dfs(v); for (int j = 0; j <= v >> 5; ++j) f[u][j] |= f[v][j]; } for (int j = 0; j <= u >> 5; ++j) for (int i = 0; i < 32; ++i) if (f[u][j] & (1 << i)) ans[rmp[u]] += w[rmp[(j << 5) + i]]; }
intmain(){ int T, N, M;
cin >> T; for (int _T = 0; _T < T; ++_T) { cin >> N >> M; if (_T) init(N); for (int i = 1; i <= N; ++i) cin >> w[i]; for (int i = 1, u, v; i <= M; ++i) { cin >> u >> v; G[u].push_back(v); R[v].push_back(u); ++outd[u]; }
for (int i = 1; i <= N; ++i) if (!outd[i]) s[++top] = i; for (int i = 1, u; top; ) { u = s[top--], mp[u] = i, rmp[i] = u, ++i; for (int v : R[u]) if (!--outd[v]) s[++top] = v; } for (int u = 1; u <= N; ++u) for (int v : G[u]) D[mp[u]].push_back(mp[v]); for (int i = 1; i <= N; ++i) std::sort(D[i].rbegin(), D[i].rend()); for (int i = N; i; --i) if (!vis[i]) dfs(i);
for (int i = 1; i <= N; ++i) cout << ans[i] << ' '; cout << '\n'; } return0; }
cin >> N >> M; for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) if (cin.get()) z[j] |= 1 << i; for (int i = 0; i < M; ++i) ++a[z[i]]; N_ = N, N = 1 << N; for (int i = 0; i < N; ++i) b[i] = b[i >> 1] + (i & 1); for (int i = 0; i < N; ++i) b[i] = std::min(b[i], N_ - b[i]); XOR(N, a, 1), XOR(N, b, 1); for (int i = 0; i < N; ++i) f[i] = a[i] * b[i]; XOR(N, f, 0);
std::cout << *std::min_element(f, f + N); return0; }