QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#428042#8770. Comparatorucup-team055#AC ✓97ms13116kbC++233.3kb2024-06-01 17:06:472024-06-01 17:06:47

Judging History

你现在查看的是最新测评结果

  • [2024-06-01 17:06:47]
  • 评测
  • 测评结果:AC
  • 用时:97ms
  • 内存:13116kb
  • [2024-06-01 17:06:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < (b); i++)
#define all(a) begin(a), end(a)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) { if(a <= b) return 0; a = b; return 1; }
bool chmax(auto& a, auto b) { if(a >= b) return 0; a = b; return 1; }

using Expr = uint32_t;
string s;
bool seek(char c) {
    return sz(s) && s.back() == c;
}
char get() {
    char c = s.back();
    s.pop_back();
    return c;
}
Expr e_xor();
Expr e_paren() {
    const char c = get();
    if(c == ')') {
        Expr ans = e_xor();
        assert(get() == '(');
        return ans;
    }
    if(c == '0') return 0b0000;
    if(c == '1') return 0b1111;
    if(c == 'x') return 0b1010;
    if(c == 'y') return 0b1100;
    __builtin_unreachable();
}
Expr e_not() {
    Expr ans = e_paren();
    while(seek('!')) {
        s.pop_back();
        ans = ~ans;
    }
    return ans;
}
Expr e_iff() {
    Expr right = e_not();
    if(!seek('=')) return right;
    s.pop_back();
    Expr left = e_iff();
    return ~(left^right);
}
Expr e_and() {
    Expr right = e_iff();
    if(!seek('&')) return right;
    s.pop_back();
    Expr left = e_and();
    return left&right;
}
Expr e_or() {
    Expr right = e_and();
    if(!seek('|')) return right;
    s.pop_back();
    Expr left = e_or();
    return left|right;
}
Expr e_xor() {
    Expr right = e_or();
    if(!seek('^')) return right;
    s.pop_back();
    Expr left = e_xor();
    return left^right;
}
Expr eval(string s_) {
    s = move(s_);
    Expr ans = e_xor();
    assert(s.empty());
    return ans;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    ll N, K;
    cin >> N >> K;
    vector priority(K * 2, vector(K * 2, pair{INF, false}));
    rep(p, 0, N) {
        ll a, b;
        string expr;
        bool r;
        cin >> a >> b >> expr >> r;
        a--; b--;
        const Expr e = eval(expr);
        rep(x, 0, 2) rep(y, 0, 2) if(e & 1 << (x | y << 1)) {
            chmin(priority[a * 2 + x][b * 2 + y], pair{p, r});
        }
    }
    bool fallback;
    cin >> fallback;
    for(auto& v : priority) for(auto& x : v) chmin(x, pair{N, fallback});
    auto f = [&](ll X, ll Y) {
        static auto ps = [&] {
            vector<array<ll, 4>> ps;
            rep(x, 0, K * 2) rep(y, 0, K * 2) {
                auto [pri, val] = priority[x][y];
                ps.push_back({pri, x, y, val});
            }
            ranges::sort(ps);
            return ps;
        }();
        for(auto [_, a, b, val] : ps) {
            const bool x = (X >> (a >> 1) & 1) == (a & 1);
            const bool y = (Y >> (b >> 1) & 1) == (b & 1);
            if(x && y) return val;
        }
    };
    const ll MX = 1 << K;
    vector<bitset<1024>> F(MX);
    rep(x, 0, MX) rep(y, 0, MX) F[x][y] = f(x, y);

    cout << [&]{
        ll ans = 0;
        rep(x, 0, MX) ans += F[x][x];
        return ans;
    }() << " " << [&]{
        ll ans = 0;
        rep(x, 0, MX) rep(y, 0, MX) ans += F[x][y] && F[y][x];
        return ans;
    }() << " " << [&]{
        ll ans = 0;
        rep(x, 0, MX) rep(y, 0, MX) if(F[x][y]) ans += (~F[x] & F[y]).count();
        return ans;
    }() << "\n";
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3852kb

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: 3628kb

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: 15ms
memory: 3708kb

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: 97ms
memory: 3604kb

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: 0ms
memory: 5328kb

input:

1 3
1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3564kb

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: 3596kb

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: 1ms
memory: 3564kb

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: 3660kb

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: 8ms
memory: 3768kb

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: 0ms
memory: 3860kb

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: 4ms
memory: 13116kb

input:

1 1
1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 66ms
memory: 3600kb

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: 3828kb

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: 0ms
memory: 3868kb

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'