QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#93093 | #6175. 遗传密码问题 | Renshey | 100 ✓ | 52ms | 27752kb | C++23 | 1.5kb | 2023-03-31 10:48:36 | 2023-03-31 10:48:41 |
Judging History
answer
#include <bits/stdc++.h>
int map (char c)
{
if (c == 'A') return 0;
if (c == 'C') return 1;
if (c == 'G') return 2;
if (c == 'T') return 3;
}
const long long inf = 1LL << 60;
const int maxn = 1 << 19;
struct Trie
{
int tot, ch[maxn][4]; long long min[maxn];
void build (void) {tot = 1;}
void clear (void) {for (int i = 1; i <= tot; i++) ch[i][0] = ch[i][1] = ch[i][2] = ch[i][3] = 0;}
} Tr[2];
int n, m, q; char S[maxn], T[maxn]; long long f[maxn];
void solve (void)
{
scanf("%s%d", S + 1, &q); n = strlen(S + 1);
Tr[0].build(); Tr[1].build();
for (int i = 1; i <= q; i++)
{
long long w; scanf("%s%lld", T + 1, &w); m = strlen(T + 1);
for (int j = 1, u = 1; j <= m; j++)
{
int &k = Tr[0].ch[u][map(T[j])];
if (!k) Tr[0].min[k = ++Tr[0].tot] = inf;
u = k; Tr[0].min[u] = std::min(Tr[0].min[u], w);
}
for (int j = m, u = 1; j >= 1; j--)
{
int &k = Tr[1].ch[u][map(T[j])];
if (!k) Tr[1].min[k = ++Tr[1].tot] = inf;
u = k; Tr[1].min[u] = std::min(Tr[1].min[u], w);
}
}
for (int i = 1; i <= n; i++) f[i] = inf;
for (int i = 0; i <= n; i++)
{
for (int u = 1, j = i; j >= 1 and Tr[1].ch[u][map(S[j])]; j--) f[i] = std::min(f[i], f[j - 1] + Tr[1].min[u = Tr[1].ch[u][map(S[j])]]);
for (int u = 1, j = i + 1; j <= n and Tr[0].ch[u][map(S[j])]; j++) f[j] = std::min(f[j], f[i] + Tr[0].min[u = Tr[0].ch[u][map(S[j])]]);
}
printf("%lld\n", f[n] == inf ? -1 : f[n]);
Tr[0].clear(); Tr[1].clear();
}
signed main ()
{
int T;
for (scanf("%d", &T); T--; ) solve();
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 4ms
memory: 14016kb
input:
10 TGTTCTGAACCACCATGGTGTCCTTGACTAGGGTGCTAAACCAAATCCTGGGTAGCCCGAGAGCAGTACCCGAGCGCAGGGGACGTCCAAA 18 GAAACG 872707675 TACTT 679726598 GTAAA 723748135 TGACG 461452620 TAGACC 719002639 GAGTGT 398114360 CGTGAC 37546213 TGACAT 219353887 CGCGC 465810039 ATGCT 773690110 ATAC 303269549 GCTACC 622915976 TTCTAA...
output:
6765079310 5065843272 6342056657 7741599583 5157680965 12151903110 1245304582 10253088049 8117317044 7062291432
result:
ok 10 numbers
Test #2:
score: 10
Accepted
time: 2ms
memory: 14064kb
input:
10 GGTCTAGAGTATAAAATACTAGTGAAAAGGTCAGACTTCGAGCTGGTGCTCAGAAGGGTTTGATGAAGTGCCAAACTACAATCCAAAGGTTAATTAGTTACACCTAAAGGCAGGACAGTTTTCGGCGGAATAACATTCGCACGTTGAATTATTTGGCTTAGCTTGACAGATAGGTCAGGAGTCACAAAAAGTGGCAGGATTGGATTGCATGTTAAAGCATAAGTGAGCGAGCCGGCACCCACGCGTGTGCTACGTTGCTCCACACAATGATGAGCGCGTTCCAGGAATCTCAACCTG...
output:
149102664725 14898785590 92286311172 130180082392 117423146611 118197799738 124348592127 172913251428 66304188543 56639086523
result:
ok 10 numbers
Test #3:
score: 10
Accepted
time: 1ms
memory: 13840kb
input:
10 AGATTCTAGTCGATCGTCATCATATGCTCGTGGTGTATGCCAACGCCCCCGTGTCCTGGAACATAAACAAACTATCTCGAAACGTCAACGGGATGACTTAACGACCGATCGTGACGATACCAGAAGGGCTATAGACACAGTGACTAATTATCCTACCAAACTTTATGTGCGACGTGACCGTAACGGGATTGCCACTCTTCCTGCCAGGGGTACCCCTTACAGATTGTTGACGCACATTTTATATGGACCTACTTTCAAGAGTGGACATCTTCGGAGATTCCGGACCGGACAATGTCC...
output:
235746326088 123826832039 385120527672 127227771541 181178785515 320080297686 246277451657 22924672297 65068708775 -1
result:
ok 10 numbers
Test #4:
score: 10
Accepted
time: 23ms
memory: 12640kb
input:
10 GTGTTGGCAAAGAATGCAGCAGCTTATTAAGCCGAAAGTGATCAGCGGGGCTAAATGACCGTAATCGGGGCGACTCGAACACACACTCGCGGCCGGCCAAGAACCTGAACCACCGGAAGTTCAGCCTTTCTTCGAGAAATCGTGCATCACATTATAATAACCACCCTCTATGCACTGCGGGGGCCTTACAAGCTCTCGGGCTATCGGAATAGAGTCGTGCACACCATATTAGTGCTCGAACTACTACTTGAAAGCCGCAAGGCAGGCCGCCTATAGAGTTAGTACACAAAACAATAC...
output:
7277903541780 5463135178879 2794921510309 1563143610532 -1 2381532320632 6250347578261 1176229304495 3056675079810 3717182148878
result:
ok 10 numbers
Test #5:
score: 10
Accepted
time: 24ms
memory: 14408kb
input:
5 TTTGCTTTGGCCTTTATGGGCGACCCTATGAGCACAGGCACAACTGAGTTCAGCCAATGCTAGGTGATGCATAGGGTAGTGAGCCTCGCGCATCTTGGGATTACCAACCCAGACCCTGTCTAATGCCATCCATGTCTCATATCTGCTAACCTCCTAAGGCTGCTGCCATCTGTATCAATATTGGTGCTAAACTTAGCTTGAGGCGTGAGGGTCCTATTGTATACGTGATCTAGCCAGTGTAATAACGAGTCAACGTTCATCTGTGGAGAAAGACACTCTTCAATTTGGATGGGCCGGG...
output:
1518565725323 623639116300 2247630224229 1734773661124 1000515142029
result:
ok 5 number(s): "1518565725323 623639116300 224...229 1734773661124 1000515142029"
Test #6:
score: 10
Accepted
time: 21ms
memory: 14384kb
input:
5 TATTCTACTAGCTGAAGTACCGTGCTTCGTGATAATGGTCAGCACACCTTGAAGGCGCCTGTTTGCACAGCCTTGCGTCTGGCGCTTAGTCTCGACCCTGATGCGGAGGATCTTTTCACGATATATATGGTACAGTTATGGTTACTTATTGAGCCCGTATTTGCTATGTCAGTTAAGTCTTGCGTGGCTGTATTCCTCGAGGCGAACAAGTCATTCAACACAACATCAGGGGTGAGGCTTCTCAGCGCCCAGAAAAAACGCTAGCTACGGGGTATCTTAATATAGGCTAGTGAAGGTG...
output:
2321598457480 5424054967674 2118024396266 1195567009829 3400384003090
result:
ok 5 number(s): "2321598457480 5424054967674 21...266 1195567009829 3400384003090"
Test #7:
score: 10
Accepted
time: 33ms
memory: 19512kb
input:
3 GGTTTTCGCGCGTGTCATGAACCAGCATACGCCAGATGGAACACGGTTTAAGGGCGGGAGTTACCTTTAGGCGCATGCTGGACATCTTGAACCCGTTCCTCAGGCGGGGTTGCGAATAAAGAGTTGCAACCCCCTCCACGACCACACGATCAAGAACGATTAATATAATACGAACCCCACTAACAGGAGATCTATCTGGCAGATCTCTCCAATGTGTGACCAGTTCTAGTGGAACCGGGATGATAGACACAATGAAAGGCGGTTGTGACTTTATTAAACAACACAGTCATGTCGTTTG...
output:
355869773343 159763866384 116520030374
result:
ok 3 number(s): "355869773343 159763866384 116520030374"
Test #8:
score: 10
Accepted
time: 34ms
memory: 20236kb
input:
3 TAGCGGGCCTTTTTAAGATACTGGTGAAGGCTCGATCGACGGCTTTAATGGTATTGAAGTCGTTCGCCGTTGTCTTTATAACGCCCCGGATATGGCATCTTATAAGGTCAACAAATTGCACATATAAGCGGCTCCTCCCTTCTCTCAGTCAAGATGACTAAACCGCTGCTTACGAGCAGGAAGTCTTACGAATCCTAGTTATCCCCTACACCTTCTCCTGCTGCCTCAAGACCAGTACGGGTGAGCCATGCAGGAGATTTGAATCTTATTGAAAATAATCGCTGGAACAGAAACAGAT...
output:
432921513168 243242181221 -1
result:
ok 3 number(s): "432921513168 243242181221 -1"
Test #9:
score: 10
Accepted
time: 37ms
memory: 13664kb
input:
3 CAATTCCATGGCATCTGGCCGATAATTGACTCGATATCAGTGATCCAGCCAACTAGTGACGGCAGAGAACCGGACCCACTATGTGCATGTTGTGTGAGCAAGTCCCGTTCCTCGATCGCTTCTAGCAGAGCCGTCTTTAAACTGTATGTCTTCCCGTGCCCCCTAATTAAACCGGCCTTTCTTAACTACCGTTTGCGCAGTATCCGTGAGCGTTAGTGCCCGCAGGATTCTCCCCGAGGGCCCCTGAGCAGGTGATGCCAATGAGGCAAGAGCTCACGCTCGGCACAAAATGAAAGCG...
output:
32444137641 55814939776 -1
result:
ok 3 number(s): "32444137641 55814939776 -1"
Test #10:
score: 10
Accepted
time: 52ms
memory: 27752kb
input:
1 GGGGTATTAGCGTAAGTGTCAACCACTACAGTCAATGCTTACGGTAGAAGGTGGAATAGGACTTACAGCCCCCTCACCAACATGCCTTTTTTAAATTACGGCATCGATTGGGATTGCAATAATGCCCACTGAAGTCCAAGGGAGCGGGAGCGCTCTTTTACGTTGGGCACCATACCGTGTTCGTCAGAACCCCACGAGCTTCGATCTCTGTATATAAGTAATGGGAATCAGCAGGCGACCAGGGTCCGCTTTTGGTTCAAATCAAACGGTCACGTCTACATTGCAGGAGAGAAGTAAA...
output:
161607544918
result:
ok 1 number(s): "161607544918"