QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#430188 | #8770. Comparator | Max_s_xaM | AC ✓ | 167ms | 40348kb | C++14 | 7.1kb | 2024-06-03 15:45:00 | 2024-06-03 15:45:01 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <map>
#include <cstring>
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 = 2e5 + 10, MAXM = 1030, MAXS = 1e6 + 10;
int n, m, alt;
struct Opt
{
int x, y, a, b, t;
bool operator < (const Opt u) const
{
if (x != u.x) return x < u.x;
if (y != u.y) return y < u.y;
if (a != u.a) return a < u.a;
if (b != u.b) return b < u.b;
return 0;
}
}op[MAXM];
int tot;
map <Opt, bool> ocr;
char str[MAXS];
vector <int> st[MAXS], tmp;
inline void Solve(int X, int Y, int T)
{
int len = strlen(str + 1), lay = 0, cur;
str[0] = '(', str[++len] = ')';
for (int x = 0; x < 2; x++)
for (int y = 0; y < 2; y++)
{
st[0].clear();
for (int i = 0; i <= len; i++)
{
if (str[i] == '(') lay++;
else if (str[i] == ')')
{
// cout << "Lay " << lay << ": ";
// for (auto x : st[lay]) cout << x << ' '; cout << "\n";
tmp.clear();
for (int i = 0; i < st[lay].size(); i++)
if (st[lay][i] < 2)
{
cur = st[lay][i];
while (tmp.size() && tmp.back() == 2) cur ^= 1, tmp.pop_back();
tmp.push_back(cur);
}
else tmp.push_back(st[lay][i]);
st[lay].clear();
for (int i = 0; i < tmp.size(); i++)
if (tmp[i] < 2 && st[lay].size() && st[lay].back() == 3)
{
st[lay].pop_back(), cur = st[lay].back(), st[lay].pop_back();
st[lay].push_back(cur == tmp[i]);
}
else st[lay].push_back(tmp[i]);
tmp.clear();
for (int i = 0; i < st[lay].size(); i++)
if (st[lay][i] < 2 && tmp.size() && tmp.back() == 4)
{
tmp.pop_back(), cur = tmp.back(), tmp.pop_back();
tmp.push_back(cur & st[lay][i]);
}
else tmp.push_back(st[lay][i]);
st[lay].clear();
for (int i = 0; i < tmp.size(); i++)
if (tmp[i] < 2 && st[lay].size() && st[lay].back() == 5)
{
st[lay].pop_back(), cur = st[lay].back(), st[lay].pop_back();
st[lay].push_back(cur | tmp[i]);
}
else st[lay].push_back(tmp[i]);
tmp.clear();
for (int i = 0; i < st[lay].size(); i++)
if (st[lay][i] < 2 && tmp.size() && tmp.back() == 6)
{
tmp.pop_back(), cur = tmp.back(), tmp.pop_back();
tmp.push_back(cur ^ st[lay][i]);
}
else tmp.push_back(st[lay][i]);
st[lay].clear();
// cout << lay << ' ' << tmp[0] << '\n';
st[--lay].push_back(tmp[0]);
}
else if (str[i] == '0' || str[i] == '1' || str[i] == 'x' || str[i] == 'y')
st[lay].push_back(str[i] == 'x' ? x : (str[i] == 'y' ? y : str[i] - '0'));
else if (str[i] == '!') st[lay].push_back(2);
else if (str[i] == '=') st[lay].push_back(3);
else if (str[i] == '&') st[lay].push_back(4);
else if (str[i] == '|') st[lay].push_back(5);
else st[lay].push_back(6);
}
// cout << x << ' ' << y << ' ' << st[0][0] << '\n';
if (!st[0][0]) continue;
auto tt = Opt{X, Y, x, y, T};
if (!ocr[tt]) op[++tot] = tt, ocr[tt] = 1;
}
// cout << "#\n";
}
bitset <MAXM> e[MAXM], flp;
int main()
{
// freopen("C.in", "r", stdin);
// freopen("C.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n), Read(m);
for (int i = 1, x, y, t; i <= n; i++)
{
Read(x), Read(y), Read(str + 1), Read(t);
Solve(x - 1, y - 1, t);
}
Read(alt);
for (int s = 0; s < (1 << m); s++)
for (int t = 0; t < (1 << m); t++)
{
bool flag = 0;
for (int i = 1; i <= tot; i++)
if (((s >> op[i].x) & 1) == op[i].a && ((t >> op[i].y) & 1) == op[i].b)
{
if (op[i].t) e[s].set(t);
flag = 1; break;
}
if (!flag && alt) e[s].set(t);
}
ll ans1 = 0, ans2 = 0, ans3 = 0;
for (int s = 0; s < (1 << m); s++)
{
if (e[s].test(s)) ans1++;
for (int t = 0; t < (1 << m); t++)
{
if (e[s].test(t) && e[t].test(s)) ans2++;
if (e[s].test(t)) flp = e[s], flp.flip(), ans3 += (flp & e[t]).count();
}
}
cout << ans1 << ' ' << ans2 << ' ' << ans3 << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 28520kb
input:
3 2 1 1 (x=0)&(y=1) 1 1 1 (x=1)&(y=(x^x)) 0 2 2 (x=1)|(y=0) 0 1
output:
0 0 0
result:
ok single line: '0 0 0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 28396kb
input:
4 3 2 1 x=0&(y=1) 1 1 2 !x^!!y 0 2 3 ((x|1)=y)&1&1 1 3 1 !x&!x&!x 0 1
output:
3 25 52
result:
ok single line: '3 25 52'
Test #3:
score: 0
Accepted
time: 53ms
memory: 29180kb
input:
1413 3 1 3 0 0 3 3 !x 0 2 2 x=0 1 1 2 !y^0 1 2 3 (x^1) 0 3 2 ((!0)) 1 1 1 !!1=(y) 0 2 2 !(1^x)&y 1 3 2 (y)&1|!!1 0 3 1 !x=(y&y=y) 0 2 1 (((!1)^!x)) 1 2 3 !0=(0&y)=1&y 0 1 2 ((((!0)))|!1) 0 3 1 !(y=!1=x|(!x)) 0 1 1 ((((y=!y)))&!0) 0 2 3 ((y=1)^!1^!!1|0) 1 2 3 1|(!x)&!x|1|(x=1) 1 2 3 !0^!!!!y&0=(!1&!0...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #4:
score: 0
Accepted
time: 167ms
memory: 29516kb
input:
181737 10 5 2 1 1 1 10 !1=!x 0 10 1 (1^x) 0 2 4 !1 1 10 8 y=(!1)^1 1 6 2 !((x&!x)) 1 1 10 !!((!x)|x) 1 7 10 (((0))) 0 7 3 !(1)^!x 0 10 4 (!1)&x 0 7 7 !y&!0 1 8 8 !1=(x)|1^1 1 2 6 ((!!!x)) 0 7 2 1 1 2 2 y=1=0 0 6 3 (!0) 0 6 4 0 0 1 1 (!1) 1 1 8 y 1 3 5 !x|!x^!1 0 4 7 (!0) 0 3 4 !1&1&!1|!0 1 2 7 ((0|1...
output:
1024 1048576 0
result:
ok single line: '1024 1048576 0'
Test #5:
score: 0
Accepted
time: 18ms
memory: 40348kb
input:
1 3 1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...
output:
4 16 0
result:
ok single line: '4 16 0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 29096kb
input:
1 1 1 1 x^y|1 0 1
output:
1 1 0
result:
ok single line: '1 1 0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 28796kb
input:
1 1 1 1 x&y|1 0 1
output:
0 0 0
result:
ok single line: '0 0 0'
Test #8:
score: 0
Accepted
time: 3ms
memory: 29752kb
input:
1 1 1 1 x=y|1 0 1
output:
0 0 0
result:
ok single line: '0 0 0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 28468kb
input:
2 2 1 2 !x&!y 1 1 1 !x&y 0 1
output:
4 12 2
result:
ok single line: '4 12 2'
Test #10:
score: 0
Accepted
time: 18ms
memory: 28196kb
input:
2 10 9 8 ((((!((!x=1))^(!1&(x|x|!y))&((!y&!x=(x=y)))&!((((x=1))&(0=(y))^(!!(!!x^1=x)&(x)^y&1=!x&1=(((!0^(1)^1))^!(((((y))|x|!y))))^!!0=!y&(0)|(y=x&!y&y=x)))=((((!!y&!!0|!0^!0)=!x))))^0&(((!1=!(!x)))|(((((x=1|!y|y)=(!1^1^0^(0)))=!0^1)))=(!(!1^(((((!1)^!x^0))))=(1)^((((y=((x))|(0)|(!1^1)))|(!!!y))=((!...
output:
0 0 0
result:
ok single line: '0 0 0'
Test #11:
score: 0
Accepted
time: 7ms
memory: 28780kb
input:
4 3 1 1 !!!!!!x 0 2 1 !!y 1 1 2 !!!!!x 1 2 2 !!!x 0 1
output:
4 16 0
result:
ok single line: '4 16 0'
Test #12:
score: 0
Accepted
time: 14ms
memory: 32376kb
input:
1 1 1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
output:
1 1 0
result:
ok single line: '1 1 0'
Test #13:
score: 0
Accepted
time: 89ms
memory: 29716kb
input:
200000 10 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10 !x^!y 1 3 10...
output:
512 262144 134217728
result:
ok single line: '512 262144 134217728'
Test #14:
score: 0
Accepted
time: 0ms
memory: 29440kb
input:
10 3 3 1 (!x) 1 3 2 !1&x&1&!y 1 2 1 ((x)&y) 1 1 3 0 0 2 2 !1&0=y&0 1 3 3 (!y)^y 1 2 1 0|((!y)) 0 3 2 x 0 2 2 (y|1^x) 0 2 1 ((!0)|y) 0 1
output:
8 64 0
result:
ok single line: '8 64 0'
Test #15:
score: 0
Accepted
time: 5ms
memory: 28500kb
input:
0 3 1
output:
8 64 0
result:
ok single line: '8 64 0'