QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#878692 | #3086. Edge Subsets | ningago | WA | 6ms | 14216kb | C++14 | 6.9kb | 2025-02-01 16:51:50 | 2025-02-01 16:51:57 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
return getchar();
#else
if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}
void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;
void putc(char c)
{
#ifdef LOCAL
putchar(c);
#else
*oS++ = c;
if(oS == oT) Flush();
#endif
#define putchar ERR
}
template <typename T = int> T read()
{
T x = 0, f = 1; char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
top = 0;
if(x < 0) putc('-'), x = -x;
if(!x) sta[top = 1] = 0;
for(; x; x /= 10) sta[++top] = x % 10;
for(; top; ) putc(sta[top--] ^ 48);
if(c) putc(c);
}
int readstr(char *s, int base)
{
int idx = base - 1; char c = getc();
for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
for(; isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
return idx - base + 1;
}
void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
for(; *s; s++)
{
if(*s != '%') { putc(*s); continue; }
s++; if(*s == 'd') print(x, 0);
else if(*s == 'c') putc(x);
printf(s + 1, rest ...);
return;
}
}
template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }
#define N 210
int left[N][N], up[N][N];
int right[N][N], down[N][N];
int sta[N];
int calc(int n, std::vector <pii> evec, int A, int B)
{
int inv = 1; for(int i = 1; i <= n; i++) if(1ll * A * i % B == 1) inv = i;
for(int i = 0; i < B; i++) for(int j = 0; j <= n / B; j++) right[i][j] = down[i][j] = left[i][j] = up[i][j] = 0;
for(pii t : evec)
{
int x, y;
x = 1ll * (t.fi % B) * inv % B;
y = t.fi / B;
// printf("[%d %d] - ", x, y);
if(t.se - t.fi == B) right[x][y] = 1;
else down[x][y] = 1;
x = 1ll * (t.se % B) * inv % B;
y = t.se / B;
if(t.se - t.fi == B) left[x][y] = 1;
else up[x][y] = 1;
// printf("[%d %d]\n", x, y);
}
for(int i = 0; i < B; i++) sta[i] = 1ll * i * inv % B;
static int dp[2][1 << 20], tmp[1 << 20], op;
if(B <= 20)
{
for(int i = 0; i < (1 << B); i++) dp[0][i] = dp[1][i] = 0;
dp[op = 0][0] = 1;
for(int j = 0; j <= n / B; j++)
{
for(int S = 0; S < (1 << B); S++) tmp[S] = dp[op][S];
auto DP = [&]() -> void
{
for(int i = B - 1; ~i; i--)
{
op ^= 1;
for(int S = 0; S < (1 << B); S++) dp[op][S] = 0;
for(int S = 0; S < (1 << B); S++) if(!(S >> i & 1)) dp[op][S] = sm(dp[op ^ 1][S] + dp[op ^ 1][S ^ (1 << i)]);
if(left[i][j])
{ for(int S = 0; S < (1 << B); S++) if(S >> i & 1) plus_(dp[op][S], dp[op ^ 1][S ^ (1 << i)]); }
if(i && up[i][j] && sta[i] < A)
{ for(int S = 0; S < (1 << B); S++) if((S >> i & 1) && (S >> (i - 1) & 1)) plus_(dp[op][S], dp[op ^ 1][S ^ (1 << i) ^ (1 << (i - 1))]), plus_(dp[op][S], dp[op ^ 1][S ^ (1 << (i - 1))]); }
if(i != B - 1 && down[i][j] && sta[i + 1] >= A)
{ for(int S = 0; S < (1 << B); S++) if((S >> i & 1) && (S >> (i + 1) & 1)) plus_(dp[op][S], dp[op ^ 1][S ^ (1 << i) ^ (1 << (i + 1))]), plus_(dp[op][S], dp[op ^ 1][S ^ (1 << (i + 1))]); }
// for(int S = 0; S < (1 << B); S++) printf("dp[%d, %d][%d] = %d\n", i, j, S, dp[op][S]);
}
};
DP();
for(int S = 0; S < (1 << B); S++) std::swap(tmp[S], dp[op][S]);
op ^= 1; for(int S = 0; S < (1 << B); S++) dp[op][S] = 0;
if(up[0][j])
{ int x = B - 1; for(int S = 0; S < (1 << B); S++) if(S >> x & 1) dp[op][S] = dp[op ^ 1][S ^ (1 << x)]; }
DP();
for(int S = 0; S < (1 << B); S++) if(S & 1) dp[op][S] = dp[op][S ^ 1], dp[op][S ^ 1] = 0;
for(int S = 0; S < (1 << B); S++) plus_(dp[op][S], tmp[S]);//, printf("dp[%d][%d] = %d (%d)\n", j, S, dp[op][S], tmp[S]);
}
int ans = 0;
for(int S = 0; S < (1 << B); S++) plus_(ans, dp[op][S]);
return ans;
}
else
{
int m = n / B + 1, ans = 0;
for(int T = 0; T < (1 << m); T++)
{
for(int S = 0; S < (1 << m); S++) dp[0][S] = dp[1][S] = 0;
dp[op = 0][T] = 1;
for(int i = 0; i < B; i++)
{
for(int j = m - 1; ~j; j--)
{
op ^= 1;
for(int S = 0; S < (1 << m); S++) dp[op][S] = 0;
for(int S = 0; S < (1 << m); S++) if(!(S >> j & 1)) dp[op][S] = sm(dp[op ^ 1][S] + dp[op ^ 1][S ^ (1 << j)]);
if(j != m - 1 && right[i][j])
{ for(int S = 0; S < (1 << m); S++) if((S >> j & 1) && (S >> (j + 1) & 1)) plus_(dp[op][S], dp[op ^ 1][S ^ (1 << j) ^ (1 << (j + 1))]), plus_(dp[op][S], dp[op ^ 1][S ^ (1 << (j + 1))]); }
if(up[i][j] && sta[i] < A)
{ for(int S = 0; S < (1 << m); S++) if((S >> j & 1) && (S >> (j - 1) & 1)) plus_(dp[op][S], dp[op ^ 1][S ^ (1 << j) ^ (1 << (j - 1))]), plus_(dp[op][S], dp[op ^ 1][S ^ (1 << (j - 1))]); }
if(up[i][j] && sta[i] >= A)
{ for(int S = 0; S < (1 << m); S++) if(S >> j & 1) plus_(dp[op][S], dp[op ^ 1][S ^ (1 << j)]); }
}
}
plus_(ans, dp[op][T]);
}
return ans;
}
}
std::vector <pii> evec[N];
int gcd(int x, int y) { for(; y; x %= y, x ^= y ^= x ^= y); return x; }
void solve()
{
// memset(h, idx = -1, sizeof(h));
int n = read(), m = read(), A = read(), B = read(), g = gcd(A, B);
for(int i = 1, x, y; i <= m; i++) x = read() - 1, y = read() - 1, evec[x % g].push_back(mkp(x / g, y / g));
int ans = 1;
for(int i = 0; i < g; i++) mul_(ans, calc(n / g, evec[i], A / g, B / g));
print(ans, '\n');
}
void init()
{
}
char _ED_;
void mian()
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
init();
for(int T = 1; T; solve(), T--);
}
#ifdef int
#undef int
#endif
}
int main()
{
uvu::mian(); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 14216kb
input:
50 97 31 32 5 37 15 46 2 33 15 46 6 37 14 46 1 32 2 34 5 36 1 32 5 37 3 35 11 42 12 44 2 33 1 33 10 42 3 35 12 43 14 46 18 49 2 34 1 33 12 43 15 47 13 45 12 44 11 42 9 41 1 32 7 39 3 35 4 35 11 43 11 42 13 45 2 34 12 43 6 38 18 50 3 35 4 36 13 45 17 49 12 43 3 34 15 46 3 34 1 32 11 42 4 35 2 34 10 4...
output:
28284459
result:
ok single line: '28284459'
Test #2:
score: -100
Wrong Answer
time: 6ms
memory: 12172kb
input:
62 19 4 30 54 58 9 13 24 54 3 7 23 53 55 59 29 33 15 45 5 35 13 17 51 55 56 60 1 31 19 49 52 56 1 31 28 58 39 43 46 50
output:
51840
result:
wrong answer 1st lines differ - expected: '69120', found: '51840'