QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418140 | #8713. 不要玩弄字符串 | light_ink_dots | AC ✓ | 878ms | 158752kb | C++14 | 3.2kb | 2024-05-23 11:15:34 | 2024-05-23 11:15:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
static const int maxk = 18, maxu = 150;
int k;
scanf("%d", &k);
static int v[1 << maxk];
static int nxt[maxu][2], id[maxu], cnt = 1;
nxt[1][0] = ++cnt, nxt[1][1] = ++cnt;
for (int i = 0; i < k; i++) {
static char s[maxu];
scanf("%s", s + 1), scanf("%d", v + (1 << i));
int l = strlen(s + 1), u = 1;
for (int p = 1; p <= l; p++) {
int d = s[p] == '1';
if (!nxt[u][d])
nxt[u][d] = ++cnt;
u = nxt[u][d];
}
id[u] ^= 1 << i;
}
queue<int> Q;
static int fa[maxu], dep[maxu];
for (int i : nxt[1]) fa[i] = dep[i] = 1, Q.push(i);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
for (int d = 0; d < 2; d++)
if (nxt[u][d])
dep[nxt[u][d]] = dep[fa[nxt[u][d]] = nxt[fa[u]][d]] + 1, Q.push(nxt[u][d]);
else
nxt[u][d] = nxt[fa[u]][d];
}
static int c[maxu], ord[maxu];
for (int i = 1; i <= cnt; i++) c[dep[i]]++;
for (int i = 1; i <= cnt; i++) c[i] += c[i - 1];
for (int i = 1; i <= cnt; i++) ord[c[dep[i]]--] = i;
for (int i = 1; i <= cnt; i++) id[ord[i]] |= id[fa[ord[i]]];
for (int s = 1; s < 1 << k; s++) v[s] = v[s ^ (s & -s)] + v[s & -s];
static int dp[1 << maxk][maxu];
for (int s = (1 << k) - 2; s >= 0; s--) {
static int deg[maxu];
static vector<int> G[maxu];
memset(dp[s], 0xcf, sizeof(dp[s]));
for (int u = 1; u <= cnt; u++) deg[u] = 0, G[u].clear();
for (int u = 1; u <= cnt; u++) {
int t0 = nxt[u][0], t1 = nxt[u][1];
if (id[t0] & ~s)
dp[s][u] = max(dp[s][u], v[id[t0] & ~s] - dp[s | id[t0]][t0]);
else
G[t0].push_back(u), deg[u]++;
if (id[t1] & ~s)
dp[s][u] = max(dp[s][u], v[id[t1] & ~s] - dp[s | id[t1]][t1]);
else
G[t1].push_back(u), deg[u]++;
}
struct node {
int u, d;
inline bool operator<(const node rhs) const { return abs(d) < abs(rhs.d); }
};
priority_queue<node> Q;
static bool vis[maxu];
memset(vis, 0, sizeof(vis));
for (int u = 1; u <= cnt; u++)
if (!deg[u] || dp[s][u] > 0)
Q.push({ u, dp[s][u] });
while (!Q.empty()) {
int u = Q.top().u;
Q.pop();
if (vis[u])
continue;
vis[u] = true;
for (int i : G[u]) {
dp[s][i] = max(dp[s][i], -dp[s][u]);
if (!(--deg[i]) || dp[s][i] > 0)
Q.push({ i, dp[s][i] });
}
}
for (int u = 1; u <= cnt; u++)
if (deg[u])
dp[s][u] = max(dp[s][u], 0);
}
int q;
scanf("%d", &q);
while (q--) {
static char s[maxu];
scanf("%s", s + 1);
int l = strlen(s + 1), S = 0, u = 1;
for (int i = 1; i <= l; i++) S |= id[u = nxt[u][s[i] == '1']];
printf("%d\n", dp[S][u]);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5876kb
input:
3 11 1 0 2 000 3 2 0 1
output:
-1 3
result:
ok 2 number(s): "-1 3"
Test #2:
score: 0
Accepted
time: 307ms
memory: 158460kb
input:
18 111101 -31301 1101101 53902 101001 77190 1000110 -26277 01010 84183 0111001 -89769 100100 31681 00101 -33612 00101000 -25238 00111 -93542 0001101 45298 01100010 63521 11001001 84789 001011 89827 11010101 -12647 01011100 18677 010100 174 10011111 -73155 524286 0 1 00 10 01 11 000 100 010 110 001 1...
output:
0 0 0 0 0 0 0 0 0 0 0 77190 0 0 0 0 0 0 0 -77190 0 0 0 0 84183 77190 0 0 0 0 0 0 0 0 0 77190 0 0 0 31681 0 -77190 0 0 0 0 0 26277 0 53108 89827 84183 77190 77190 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77190 77190 0 0 0 0 0 0 31681 -53108 0 0 -77190 -77190 0 0 0 0 0 0 0 0 0 0 26277 26277 0 0 53108 53108...
result:
ok 524286 numbers
Test #3:
score: 0
Accepted
time: 676ms
memory: 158748kb
input:
18 01 3 000 13 100 9 011 1 0101 6 0011 16 0100 12 0111 10 00100 15 1110 2 011111 18 100100 6 1010001 8 10101100 3 1001000 9 00100001 12 001100 8 10111111 2 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1011 0111 1111 00000 100...
output:
10 0 10 10 -7 0 3 13 13 10 9 -7 8 0 3 0 13 13 20 13 8 12 0 9 -7 -7 8 8 2 0 3 0 0 0 16 13 13 13 33 8 8 13 9 8 0 12 0 9 9 9 -7 -7 -8 -9 17 8 8 8 2 2 16 0 3 0 0 0 -3 0 0 0 3 25 13 13 8 13 13 13 33 24 6 8 8 8 14 15 17 8 8 8 0 0 0 12 0 9 9 9 9 9 8 7 -16 0 -7 -7 -8 -8 0 -9 17 8 8 8 8 8 8 10 -7 2 2 2 16 16...
result:
ok 524286 numbers
Test #4:
score: 0
Accepted
time: 785ms
memory: 158516kb
input:
18 01 12 100 19 110 17 011 8 0010 10 1101 20 1110 4 1011 19 00101 16 1000 10 001110 1 110010 7 0011111 11 01101011 8 0011111 9 10011110 11 011101 4 01011000 1 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1011 0111 1111 00000 ...
output:
12 -6 11 11 0 6 11 8 9 11 1 26 8 10 11 2 10 8 9 9 9 11 1 16 26 27 8 1 12 10 11 2 0 2 10 10 10 8 9 -6 9 9 9 20 9 11 1 10 16 27 26 26 19 27 8 8 1 0 13 -1 12 10 11 2 0 2 0 0 0 2 10 10 10 10 10 4 10 8 9 0 -6 -10 9 9 9 9 9 9 20 9 9 24 9 11 1 10 10 10 6 16 20 27 26 22 26 27 19 0 19 27 8 16 8 8 1 1 0 0 13 ...
result:
ok 524286 numbers
Test #5:
score: 0
Accepted
time: 234ms
memory: 158752kb
input:
18 0010 -4 100 -4 1 4 010 -1 111 -3 0110 7 011 -5 1010 -1 1000 3 0 3 0000 -3 0111 3 11 7 101 10 00 -4 01 -1 1001 5 1111 10 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1011 0111 1111 00000 10000 01000 11000 00100 10100 01100 ...
output:
-2 15 2 11 5 -8 -2 6 11 11 5 -2 -3 10 0 -3 6 6 11 0 10 11 5 5 -1 -2 -3 7 10 0 0 0 -3 1 6 9 6 6 11 11 0 0 10 0 12 11 5 5 5 -2 -1 0 0 -2 -3 -3 7 7 10 10 0 0 0 0 0 1 -3 4 -3 1 6 6 9 9 6 5 6 12 11 11 11 11 0 0 0 0 10 10 0 0 12 2 12 11 5 5 5 -2 5 -4 10 -2 -1 -1 0 0 0 0 -2 -2 -3 -3 -3 -3 7 7 0 7 10 10 10 ...
result:
ok 524286 numbers
Test #6:
score: 0
Accepted
time: 320ms
memory: 158460kb
input:
18 00001110 18 10101000 11 01111011 20 00110100 -4 01011010 -4 11001100 3 11001011 7 00010010 4 11110001 0 00110010 19 01101111 14 00001011 -7 00000001 -8 11110111 15 00010001 -10 10111101 13 11101000 5 01010000 15 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 5...
result:
ok 524286 numbers
Test #7:
score: 0
Accepted
time: 66ms
memory: 8088kb
input:
10 11 15 011 3 000 3 011 13 0110 8 1101 12 0101 3 1101 12 10101 4 1010 15 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1011 0111 1111 00000 10000 01000 11000 00100 10100 01100 11100 00010 10010 01010 11010 00110 10110 01110 1...
output:
-3 15 3 -3 31 0 0 3 -3 8 31 31 0 0 0 0 3 3 -3 -3 16 8 31 31 31 16 0 0 0 0 0 0 0 0 3 3 3 3 0 -3 -3 -1 16 16 16 8 31 31 31 16 31 31 8 16 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 0 0 -3 -3 -3 -3 7 -1 16 16 13 -3 16 16 16 8 31 31 31 16 31 31 3 16 31 31 31 8 8 8 8 16 0 0 0 0 0 0 3 11 0 0 0 3 0 0 ...
result:
ok 524286 numbers
Test #8:
score: 0
Accepted
time: 878ms
memory: 158456kb
input:
18 10 1 100 10 0011 8 0001 8 0101 20 1001 13 01101 15 1101110 11 01101000 14 110011 10 00110110 11 1010011 7 10000011 19 1101010 6 01011111 3 00010010 7 00100001 15 00010110 15 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 101...
output:
0 0 0 5 0 0 0 5 23 10 8 0 0 0 0 0 5 0 23 23 14 10 8 8 -3 1 0 0 0 0 0 0 0 0 5 0 0 0 23 20 10 23 19 14 10 10 8 11 8 18 -3 -3 1 1 0 0 3 -1 0 0 0 0 0 0 0 0 -3 0 0 0 5 0 0 0 3 0 0 0 23 20 20 20 10 10 23 23 19 18 15 14 7 10 10 10 8 11 11 11 8 15 18 18 -3 0 -3 -3 -4 1 1 1 0 -3 0 0 3 3 -1 -1 0 0 -3 1 0 0 0 ...
result:
ok 524286 numbers
Test #9:
score: 0
Accepted
time: 666ms
memory: 158456kb
input:
18 11 17 011 20 0110 20 0001 12 0111 13 0110 13 00010 4 0001110 19 01010101 3 001111 17 11011001 14 1111001 12 01111110 14 0011011 3 11000011 3 10010111 11 01001100 11 10110101 7 524286 0 1 00 10 01 11 000 100 010 110 001 101 011 111 0000 1000 0100 1100 0010 1010 0110 1110 0001 1001 0101 1101 0011 1...
output:
5 17 -5 5 11 0 5 -5 5 0 11 17 26 0 5 5 -5 1 5 5 7 0 7 11 17 0 26 20 -3 0 5 5 5 11 -5 -5 -4 1 0 5 5 1 7 13 3 0 7 7 18 -1 17 17 -7 0 30 26 20 20 14 -3 3 0 5 5 5 11 5 5 9 11 0 -5 -5 -1 -4 -4 3 13 0 0 5 1 5 5 7 1 3 7 13 13 3 3 3 0 7 7 7 1 18 18 4 -1 14 10 17 0 -7 -13 -3 0 30 30 19 26 20 20 13 20 16 14 -...
result:
ok 524286 numbers
Extra Test:
score: 0
Extra Test Passed