QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863130 | #2824. 找树 | qojszt | WA | 417ms | 89596kb | C++20 | 2.6kb | 2025-01-19 13:27:55 | 2025-01-19 13:28:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int M = 998244353;
int add(int x, int y){x += y;return x >= M? x - M : x;}
int sub(int x, int y){x -= y;return x < 0? x + M : x;}
int mul(int x, int y){return static_cast<long long>(x) * y % M;}
void Or(int &a, int &b, int tg){b = tg == 1? add(b, a) : sub(b, a);}
void And(int &a, int &b, int tg){a = tg == 1? add(a, b) : sub(a, b);}
void Xor(int &a, int &b, int tg){tie(a, b) = make_pair(mul(add(a, b), tg), mul(sub(a, b), tg));}
int fpw(int x, int y){int ret = 1;for (; y; y >>= 1, x = mul(x, x))if (y & 1)ret = mul(ret, x);return ret;}
constexpr int half = M + 1 >> 1;
void trans(int *a, int n, bool rev, string o){
for (int k = 1; k < n; k <<= 1){
char c = o[__builtin_ctz(k)];
for (int i = 0; i < n; i += k << 1)
for (int j = 0; j < k; ++j){
if (c == '|')Or(a[j + k], a[i + j + k], rev? -1 : 1);
if (c == '&')And(a[j + k], a[i + j + k], rev? -1 : 1);
if (c == '^')Xor(a[j + k], a[i + j + k], rev? half : 1);
}
}
}
int n, m, w; string o;
int det(int a[75][75], int n){
int ret = 1; --n;//ignore last line and column
for (int i = 0; i < n; ++i){
int k = i;
for (int j = i + 1; j < n; ++j)if (a[k][i])k = j;
if (i ^ k)swap(a[i], a[k]), ret = sub(0, ret);
if (!a[i][i])return 0;
ret = mul(ret, a[i][i]);int inv = fpw(a[i][i], M - 2);
for (int &v : a[i])v = mul(v, inv);
for (int j = 0; j < n; ++j)if (j ^ i && a[j][i]){
int sbv = a[j][i];
for (int k = i; k < n; ++k)a[j][k] = sub(a[j][k], mul(a[i][k], sbv));
}
}
return ret;
}
int a[75][75][1 << 12], ans[1 << 12];
int get(int x){
static int v[75][75];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)v[i][j] = a[i][j][x];
return det(v, n);
}
int main(){
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m >> o;w = o.size();
for (int i = 1, x, y, v; i <= m; ++i){
cin >> x >> y >> v;if (--x == --y)continue;
++a[x][x][v];//++deg_x
++a[y][y][v];//++deg_y
--a[x][y][v];--a[y][x][v];//link x->y
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)trans(a[i][j], 1 << w, 0, o);
for (int i = 0; i < 1 << w; ++i)ans[i] = get(i);
trans(ans, 1 << w, 1, o);
int rs = rend(ans) - find_if(rbegin(ans), rend(ans), [](int x)->bool{
return x;
}) - 1;
cout << rs << endl;
return 0;
}
/*
3 3
^
1 2 1
2 3 1
1 3 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 309ms
memory: 89596kb
input:
70 100 &&&&&&&&&&&& 59 1 577 11 18 513 41 11 6 7 33 1 25 26 577 3 57 516 28 5 3 13 56 0 2 32 7 66 53 517 42 31 519 41 34 70 37 54 579 24 15 512 70 32 512 51 49 64 55 19 69 3 31 517 24 8 582 44 45 513 47 58 517 47 41 577 33 22 519 57 41 0 70 50 67 3 6 6 14 43 6 21 1 579 32 27 576 62 7 514 39 36 69 12...
output:
-1
result:
ok single line: '-1'
Test #2:
score: 0
Accepted
time: 338ms
memory: 88940kb
input:
70 100 |&&&&|&&&^&& 70 50 200 51 46 9 48 33 163 14 64 137 53 54 96 32 24 160 7 22 8 40 66 192 12 22 74 20 25 66 7 40 97 27 13 192 3 15 96 43 16 195 23 6 74 7 34 33 5 5 98 12 26 99 44 38 8 27 44 32 10 67 42 19 12 234 6 39 65 27 24 8 58 13 106 37 69 32 4 2 163 33 65 168 3 3 107 56 65 8 42 53 137 32 53...
output:
-1
result:
ok single line: '-1'
Test #3:
score: -100
Wrong Answer
time: 417ms
memory: 89140kb
input:
70 5000 ^&&&&|^&^&&| 70 55 35 32 4 2338 1 45 33 69 4 2337 55 51 2338 26 46 2050 8 5 33 16 51 35 32 10 1 18 67 257 12 37 2307 34 6 2051 30 10 33 21 35 2082 4 27 34 12 4 2337 44 34 2082 11 17 2338 1 2 289 22 2 34 39 68 2304 11 48 289 44 26 2080 57 12 2306 69 15 2338 16 65 2 51 67 2048 1 5 291 64 48 28...
output:
-1
result:
wrong answer 1st lines differ - expected: '2339', found: '-1'