QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465753#8770. ComparatorGeothermalAC ✓205ms191708kbC++205.3kb2024-07-07 08:17:502024-07-07 08:17:50

Judging History

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

  • [2024-07-07 08:17:50]
  • 评测
  • 测评结果:AC
  • 用时:205ms
  • 内存:191708kb
  • [2024-07-07 08:17:50]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x);
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif

vector<vi> atDep[4];
string S;

int parse(int l, int r, int x, int y, int d) {
    if (l == r) {
        if (S[l] == 'x') {
            return x;
        } else if (S[l] == 'y') {
            return y;
        } else return S[l] - '0';
    }

    F0Rd(i, 4) {
        auto it = lb(all(atDep[i][d]), l);
        if (it != ub(all(atDep[i][d]), r)) {
            it = ub(all(atDep[i][d]), r);
            it--;
            int p = *it;
            int a = parse(l, p-1, x, y, d);
            int b = parse(p+1, r, x, y, d);
            if (i == 0) {
                return a==b;
            } else if (i == 1) {
                return a&b;
            } else if (i==2) {
                return a|b;
            } else return a^b;
        }
    }
    if (S[l] == '!') {
        return 1^parse(l+1, r, x, y, d);
    }
    return parse(l+1, r-1, x, y, d+1);
}

const int MX = 1<<10;

void solve() {

    int N, K; cin >> N >> K;
    int prio[K][2][K][2];
    int res[K][2][K][2];
    F0R(i, K) F0R(a, 2) F0R(j, K) F0R(b, 2) prio[i][a][j][b] = -1;

    F0R(exp, N) {
        int A, B; cin >> A >> B; A--; B--;
        cin >> S;
        int R; cin >> R;

        int d = 0;
        F0R(i, 4) atDep[i] = vector<vi>(sz(S));
        F0R(i, sz(S)) {
            int a = S[i];
            if (a == '(') {
                d++;
            } else if (a == ')') {
                d--;
            } else if (a == '=') {
                atDep[0][d].pb(i);
            } else if (a == '&') {
                atDep[1][d].pb(i);
            } else if (a == '|') {
                atDep[2][d].pb(i);
            } else if (a == '^') {
                atDep[3][d].pb(i);
            }
        }

        F0R(i, 2) {
            F0R(j, 2) {
                if (prio[A][i][B][j] != -1) continue;
                if (parse(0, sz(S) - 1, i, j, 0)) { 
                    //cout << exp << ": " << A << " " << i << " " << B << " " << j << ": " << R << endl;
                    prio[A][i][B][j] = exp;
                    res[A][i][B][j] = R;
                }
            }
        }
    }
    int de; cin >> de;

    int val[1<<K][1<<K];
    F0R(i, 1<<K) {
        F0R(j, 1<<K) {
            int p = N+1;
            int v = de;
            F0R(a, K) {
                F0R(b, K) {
                    int has1 = ((i&(1<<a))?1:0);
                    int has2 = ((j&(1<<b))?1:0);
                    if (prio[a][has1][b][has2] < p && prio[a][has1][b][has2] != -1) {
                        p = prio[a][has1][b][has2];
                        v = res[a][has1][b][has2];
                    }
                }
            }
            val[i][j] = v;
        }
    }

    int rv = 0; F0R(i, 1<<K) if (val[i][i]) rv++;
    cout << rv << " ";

    /*cout << endl;
    F0R(i, 1<<K) {
        F0R(j, 1<<K) {
            cout << val[i][j];
        }
        cout << endl;
    }*/
    int sv = 0;
    F0R(i, 1<<K) {
        F0R(j, 1<<K) {
            if (val[i][j] == 1 && 1 == val[j][i]) sv++;
        }
    }
    cout << sv << " ";

    bitset<MX> onesA[1<<K], onesB[1<<K];
    F0R(i, 1<<K) {
        F0R(j, 1<<K) {
            if (val[i][j]) {
                onesA[i].set(j);
                onesB[j].set(i);
            }
        }
    }

    int tv = 0;
    F0R(i, 1<<K) {
        F0R(j, 1<<K) {
            if (val[i][j] == 0) {
                tv += (onesA[i]&onesB[j]).count();
            }
        }
    }
    cout << tv << nl;


}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 23ms
memory: 3844kb

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: 179ms
memory: 7900kb

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: 107ms
memory: 191708kb

input:

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

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

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

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

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

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: 205ms
memory: 11836kb

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

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: 5ms
memory: 22260kb

input:

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

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 192ms
memory: 7948kb

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'