QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439283 | #8768. Arrested Development | PetroTarnavskyi# | RE | 0ms | 0kb | C++20 | 2.6kb | 2024-06-11 19:05:49 | 2024-06-11 19:05:51 |
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 200'447;
const int K = 10;
VI f[N];
string s[N];
int res[N];
int idxA[N];
int idxB[N];
int val[K][K][2][2];
void upd(int& a, int b)
{
a = min(a, b);
}
bool g(bool x, bool y, char c)
{
if (c == '=')
return x == y;
if (c == '&')
return x && y;
if (c == '|')
return x || y;
return x ^ y;
}
bool eval(int i, int l, int r, bool x, bool y)
{
//cerr << s[i] << ' ' << l << ' ' << r << '\n';
bool nt = false;
VI v;
string op = "";
FOR (j, l, r)
{
if (s[i][j] == '!')
nt ^= 1;
else if (s[i][j] == '(')
{
v.PB(eval(i, j + 1, f[i][j], x, y) ^ nt);
nt = 0;
j = f[i][j];
}
else if (s[i][j] == 'x')
{
v.PB(x ^ nt);
nt = 0;
}
else if (s[i][j] == 'y')
{
v.PB(y ^ nt);
nt = 0;
}
else if (s[i][j] == '0' || s[i][j] == '1')
{
v.PB(s[i][j] - '0');
}
else
{
//cerr << s[i][j] << '\n';
assert(s[i][j] == '=' || s[i][j] == '&' || s[i][j] == '|' || s[i][j] == '^');
op += s[i][j];
}
}
string all = "=&|^";
FOR (t, 0, 4)
{
int last = v[0];
VI v2;
string op2 = "";
FOR (j, 0, SZ(op))
{
if (op[j] == all[t])
{
last = g(last, v[j + 1], op[j]);
}
else
{
v2.PB(last);
op2 += op[j];
last = v[j + 1];
}
}
v2.PB(last);
v = v2;
op = op2;
}
//cerr << SZ(v) << ' ' << SZ(op) << '\n';
assert(SZ(v) == 1);
return v[0];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
FOR (i, 0, k) FOR (j, 0, k) FOR (vi, 0, 2) FOR (vj, 0, 2) val[i][j][vi][vj] = n;
FOR (i, 0, n)
{
cin >> idxA[i] >> idxB[i];
idxA[i]--;
idxB[i]--;
cin >> s[i];
f[i].resize(SZ(s[i]));
VI st;
FOR (j, 0, SZ(s[i]))
{
if (s[i][j] == '(')
st.PB(j);
else if (s[i][j] == ')')
{
f[i][st.back()] = j;
st.pop_back();
}
}
FOR (vi, 0, 2)
{
FOR (vj, 0, 2)
{
if (eval(i, 0, SZ(s[i]), vi, vj))
upd(val[idxA[i]][idxB[i]][vi][vj], i);
}
}
cin >> res[i];
}
cin >> res[n];
//FOR (i, 0, k) FOR (j, 0, k) FOR (vi, 0, 2) FOR (vj, 0, 2)
// cerr << i << ' ' << j << ' ' << vi << ' ' << vj << ' ' << val[i][j][vi][vj] << '\n';
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
4 100 1 1 90 1 20 1 20