QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#615792 | #9449. New School Term | ucup-team3564# | RE | 1ms | 7920kb | C++20 | 7.2kb | 2024-10-05 20:10:32 | 2024-10-05 20:10:33 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef vector <int> poly;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x *= f;
}
const int N = 2e4 + 10, MOD = 998244353, W = 5010, M = 1e6 + 10;
// inline int power(int x, int y = MOD - 2) {
// int ans = 1;
// for (; y; x = (ll) x * x % MOD, y >>= 1)
// if (y & 1) ans = (ll) ans * x % MOD;
// return ans;
// }
// namespace NTT {
// int rev[N], lim, w[2][N];
// void ntt(int *f, int flag) {
// F(i, 0, lim - 1)
// if (i < rev[i]) swap(f[i], f[rev[i]]);
// for (int len = 2, t = 1; len <= lim; len <<= 1, t <<= 1) {
// for (int i = 0; i < lim; i += len) {
// for (int j = i; j < i + t; j++) {
// int A = f[j], B = (ll) f[j + t] * w[flag < 0][t + j - i] % MOD;
// f[j] = (A + B) % MOD;
// f[j + t] = (A - B + MOD) % MOD;
// // f[j] = A + B; if (f[j] > MOD) f[j] -= MOD;
// // f[j + t] = A - B; if (f[j + t] < 0) f[j + t] += MOD;
// }
// }
// }
// if (flag < 0) {
// int t = power(lim);
// F(i, 0, lim - 1) f[i] = (ll) f[i] * t % MOD;
// }
// }
// void init(int n) {
// for (int k = 2; ; k <<= 1) {
// int m = k >> 1, v = power(3, (MOD - 1) / k), inv = power(v);
// w[0][m] = w[1][m] = 1;
// F(j, 1, m - 1)
// w[0][m + j] = (ll) w[0][m + j - 1] * v % MOD,
// w[1][m + j] = (ll) w[1][m + j - 1] * inv % MOD;
// if (k >= n) break;
// }
// }
// poly operator * (poly a, poly b) {
// int sum = SZ(a) + SZ(b);
// int s = -1;
// for (lim = 1; lim <= sum; lim <<= 1, s++);
// a.resize(lim), b.resize(lim);
// F(i, 1, lim - 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << s);
// ntt(a.data(), 1); ntt(b.data(), 1);
// F(i, 0, lim - 1) a[i] = (ll) a[i] * b[i] % MOD;
// ntt(a.data(), -1);
// a.resize(sum + 1);
// return a;
// }
// }
// using NTT::operator *;
// const int B = W / 64 + 5;
// struct Bitset {
// ull a[B];
// void reset() {
// ms(a, 0);
// }
// void flip(int x) {
// a[x >> 6] ^= 1ull << (x & 63);
// }
// void set(int x) {
// a[x >> 6] |= 1ull << (x & 63);
// }
// void reset(int x) {
// a[x >> 6] &= ~ (1ull << (x & 63));
// }
// int test(int x) {
// return (a[x >> 6] >> (x & 63)) & 1;
// }
// Bitset operator ~ () {
// Bitset ret;
// for (int i = 0; i < B; i++) ret.a[i] = ~ a[i];
// return ret;
// }
// Bitset operator & (const Bitset &b) {
// Bitset ans;
// for (int i = 0; i < B; i++) ans.a[i] = a[i] & b.a[i];
// return ans;
// }
// Bitset operator | (const Bitset &b) {
// Bitset ans;
// for (int i = 0; i < B; i++) ans.a[i] = a[i] | b.a[i];
// return ans;
// }
// Bitset operator ^ (const Bitset &b) {
// Bitset ans;
// for (int i = 0; i < B; i++) ans.a[i] = a[i] ^ b.a[i];
// return ans;
// }
// Bitset operator << (int t) {
// Bitset ret;
// ull last = 0;
// int high = t >> 6, low = t & 63;
// for (int i = 0; i + high < B; i++) {
// ret.a[i + high] = last | (a[i] << low);
// if (low) last = a[i] >> (64 - low);
// }
// return ret;
// }
// Bitset operator >> (int t) {
// Bitset ret;
// ull last = 0;
// int high = t >> 6, low = t & 63;
// for (int i = B - 1; i >= high; i--) {
// ret.a[i - high] = last | (a[i] >> low);
// if (low) last = a[i] << (64 - low);
// }
// return ret;
// }
// };
bitset <W> f[N];
int n, m, a[M], b[M], fa[N], sz[N], ff[N], ss[N];
int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
vector <int> g;
bool vis[N];
signed main() {
read(n), read(m);
F(i, 1, n * 4) fa[i] = i, sz[i] = (i <= n * 2);
F(i, 1, m) {
read(a[i]), read(b[i]);
}
F(i, 1, n * 2) g.push_back(1);
DF(i, m, 1) {
if (find(a[i]) == find(b[i]) || find(a[i]) == find(b[i] + n * 2)) continue;
// vector <int> gg = g;
// gg.erase(find(all(gg), sz[find(a[i])]));
// gg.erase(find(all(gg), sz[find(b[i])]));
// gg.erase(find(all(gg), sz[find(a[i] + n * 2)]));
// gg.erase(find(all(gg), sz[find(b[i] + n * 2)]));
// gg.push_back(sz[find(a[i])] + sz[find(b[i] + n * 2)]);
// gg.push_back(sz[find(b[i])] + sz[find(a[i] + n * 2)]);
F(i, 1, n * 4) ff[i] = fa[i], ss[i] = sz[i];
sz[find(b[i] + n * 2)] += sz[find(a[i])];
fa[find(a[i])] = find(b[i] + n * 2);
sz[find(b[i])] += sz[find(a[i] + n * 2)];
fa[find(a[i] + n * 2)] = find(b[i]);
bitset <W> u;
u.reset();
u.set(0);
int s = 0;
map <int, int> mp;
F(i, 1, n * 2) {
if (find(i) == i) {
int a = sz[i], b = sz[n * 2 + i];
if (a > b) swap(a, b);
s += a;
if (b > a) {
mp[b - a]++;
}
// u = u | (u << (b - a));
// u = (u << sz[i]) | (u << sz[n * 2 + i]);
}
}
while (mp.size()) {
auto [a, b] = * mp.begin();
if (a > n) break;
mp.erase(mp.begin());
{
int t = 1;
while (t <= b) {
if (t == 1) {
u = u | (u << a);
} else {
mp[a * t]++;
}
b -= t;
t *= 2;
}
}
if (b) {
if (b == 1) {
u = u | (u << a);
} else {
mp[a * b]++;
}
}
}
// for (int i: gg) u |= u << i;
if (u.test(n - s)) {
// debug << i << endl;
// sz[find(b[i] + n * 2)] += sz[find(a[i])];
// fa[find(a[i])] = find(b[i] + n * 2);
// sz[find(b[i])] += sz[find(a[i] + n * 2)];
// fa[find(a[i] + n * 2)] = find(b[i]);
} else {
F(i, 1, n * 4) fa[i] = ff[i], sz[i] = ss[i];
sz[find(b[i])] += sz[find(a[i])];
fa[find(a[i])] = find(b[i]);
sz[find(b[i] + n * 2)] += sz[find(a[i] + n * 2)];
fa[find(a[i] + n * 2)] = find(b[i] + n * 2);
}
// debug << a[i] << " " << b[i] << endl;
// F(j, 1, n * 2) cout << find(j) << " "; cout << endl;
}
vector <int> w;
f[0][0] = 1;
F(i, 1, n * 2) {
if (find(i) == i) {
// debug << sz[i] << " " << sz[n * 2 + i] << endl;
w.push_back(i);
f[w.size()] = (f[w.size() - 1] << sz[i]) | (f[w.size() - 1] << sz[n * 2 + i]);
// u = (u << sz[i]) | (u << sz[n + i]);
}
}
if (!f[w.size()][n]) {
while (true);
}
assert(f[w.size()][n]);
int cur = n;
DF(i, w.size(), 1) {
if (cur >= sz[w[i - 1]] && f[i - 1][cur - sz[w[i - 1]]]) {
vis[w[i - 1]] = true;
cur -= sz[w[i - 1]];
} else {
vis[w[i - 1] + n * 2] = true;
cur -= sz[w[i - 1] + n];
}
}
assert(cur == 0);
int s = 0;
F(i, 1, n * 2) cout << vis[find(i)], s += vis[find(i)];
// assert(s == n);
return 0;
}
/* why?
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7920kb
input:
2 4 1 3 2 4 1 4 1 2
output:
1010
result:
ok Output is valid. OK
Test #2:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
3 7 2 5 1 3 4 6 2 6 4 5 2 4 5 6
output:
001101
result:
ok Output is valid. OK
Test #3:
score: -100
Runtime Error
input:
1 0