QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#616014 | #9449. New School Term | 中国入民小学附属信息I队 (Zicheng Wang, Shubang Liu, Minkai Shao)# | WA | 1ms | 5688kb | C++14 | 4.7kb | 2024-10-05 21:27:15 | 2024-10-05 21:27:16 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <iomanip>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 1e4 + 10, mod = 998244353;
inline void add(int &x, int y) { (x += y) >= mod && (x -= mod); }
inline void sub(int &x, int y) { (x -= y) < 0 && (x += mod); }
int n, m, fr[MAXN], to[MAXN];
int sum;
int f[MAXN], g[MAXN];
inline void Add(int x, int y)
{
if (x > y) swap(x, y);
sum += x, y -= x;
if (!y) return;
for (int i = n - y; i >= 0; i--)
add(f[i + y], f[i]);
}
inline void Delete(int x, int y)
{
if (x > y) swap(x, y);
sum -= x, y -= x;
if (!y) return;
for (int i = 0; i <= n - y; i++)
sub(f[i + y], f[i]);
}
bool col[MAXN];
int fa[MAXN], cnt[MAXN][2];
inline int Find(int k) { return k == fa[k] ? k : fa[k] = Find(fa[k]); }
bool tp[MAXN]; int pre[MAXN];
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n), Read(m), n <<= 1;
for (int i = 1; i <= m; i++) Read(fr[i]), Read(to[i]);
f[0] = 1;
for (int i = 1; i <= n; i++) Add(0, 1), fa[i] = i, cnt[i][0] = 1;
for (int i = m; i >= 1; i--)
{
// cout << sum << '\n';
int u = fr[i], v = to[i];
// if (Find(u) == Find(v) && col[u] != col[v]) cout << u << ' ' << v << '\n';
if (Find(u) == Find(v)) continue;
int x0 = cnt[fa[u]][0], x1 = cnt[fa[u]][1];
if (col[u] == col[v]) x0 += cnt[fa[v]][1], x1 += cnt[fa[v]][0];
else x0 += cnt[fa[v]][0], x1 += cnt[fa[v]][1];
for (int j = 0; j <= n; j++) g[j] = f[j];
Delete(cnt[fa[u]][0], cnt[fa[u]][1]), Delete(cnt[fa[v]][0], cnt[fa[v]][1]), Add(x0, x1);
if (!f[(n >> 1) - sum]) { for (int j = 0; j <= n; j++) f[j] = g[j]; continue; }
else if (col[u] == col[v])
{
for (int j = 1; j <= n; j++)
if (Find(j) == fa[v]) col[j] ^= 1;
swap(cnt[fa[v]][0], cnt[fa[v]][1]);
}
// cout << u << ' ' << v << '\n';
cnt[fa[u]][0] = x0, cnt[fa[u]][1] = x1, fa[fa[v]] = fa[u];
}
for (int i = 0; i <= n; i++) f[i] = g[i] = 0;
f[0] = 1, sum = 0;
for (int i = 1; i <= n; i++)
if (fa[i] == i)
{
int x = cnt[i][0], y = cnt[i][1];
if (x > y) swap(x, y), tp[i] = 1;
sum += x, y -= x;
for (int j = n - y; j >= 0; j--)
if (!f[j + y] && f[j]) f[j + y] = 1, g[j + y] = i, pre[j + y] = j;
}
int x = (n >> 1) - sum;
while (x) tp[g[x]] ^= 1, x = pre[x];
for (int i = 1; i <= n; i++)
if (tp[Find(i)]) col[i] ^= 1;
for (int i = 1; i <= n; i++) cout << col[i]; cout << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
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: 0ms
memory: 3596kb
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: 0
Accepted
time: 1ms
memory: 5600kb
input:
1 0
output:
01
result:
ok Output is valid. OK
Test #4:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
1 1 1 2
output:
01
result:
ok Output is valid. OK
Test #5:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
2 3 2 4 3 4 1 2
output:
0110
result:
ok Output is valid. OK
Test #6:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
3 8 4 6 3 5 1 4 2 4 1 6 1 2 3 4 4 5
output:
010101
result:
ok Output is valid. OK
Test #7:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
4 9 4 7 3 8 1 5 2 7 2 8 6 8 7 8 1 4 1 6
output:
10101001
result:
ok Output is valid. OK
Test #8:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
5 16 3 6 9 10 2 7 1 10 1 5 2 10 3 5 5 6 3 4 2 5 4 5 3 8 4 7 6 8 1 6 7 10
output:
1101000101
result:
ok Output is valid. OK
Test #9:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
6 13 4 5 2 9 3 8 4 8 4 11 10 12 3 4 3 9 5 11 2 8 5 10 5 8 1 11
output:
001001110110
result:
ok Output is valid. OK
Test #10:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
12 153 1 24 16 18 7 14 1 16 20 21 9 14 21 22 4 5 17 24 4 12 5 17 13 24 14 15 12 23 12 16 8 11 14 24 9 16 2 5 6 19 11 17 4 22 4 7 6 16 7 20 8 15 5 24 2 10 10 21 21 24 1 12 11 19 18 21 18 24 12 17 13 22 7 9 13 23 4 9 11 13 15 21 5 7 2 4 15 16 17 19 11 16 11 20 7 8 4 15 13 14 6 18 2 19 9 13 23 24 4 21 ...
output:
000011100110010001111110
result:
ok Output is valid. OK
Test #11:
score: -100
Wrong Answer
time: 1ms
memory: 4064kb
input:
259 33757 472 500 65 336 138 469 307 442 427 458 43 239 17 508 460 466 108 393 79 92 250 483 44 277 17 132 35 57 155 499 184 474 246 272 274 418 457 458 338 372 196 514 31 208 117 187 90 229 153 284 189 355 16 337 146 456 269 271 279 412 305 336 303 441 399 472 85 286 91 97 157 437 137 379 71 360 27...
output:
000000000000000010000000000000000000000000000000000000001000000000000000000000000000000000010000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000100000000000000000000100000000010000000000000000011111111111101111011110111111111111111111111...
result:
wrong answer The division is not minimized.