QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107741 | #5388. Just a Quiz | PetroTarnavskyi# | AC ✓ | 137ms | 72180kb | C++17 | 2.0kb | 2023-05-22 18:03:25 | 2023-05-22 18:03:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
vector<string> str;
struct node
{
map<string, int> m;
map<int, int> ans;
int sz;
int mx;
} trie[200500];
int nx = 1;
vector<string> f(string s)
{
stringstream ss(s);
vector<string> vs;
while (!ss.eof())
{
string t;
ss >> t;
vs.PB(t);
}
return vs;
}
void add(string q, string a)
{
vector<string> vs = f(q);
int idx = lower_bound(ALL(str), a) - str.begin();
int v = 0;
FOR(i, 0, SZ(vs))
{
trie[v].ans[idx]++;
trie[v].mx = max(trie[v].mx, trie[v].ans[idx]);
trie[v].sz++;
if (trie[v].m.count(vs[i]))
v = trie[v].m[vs[i]];
else
{
trie[v].m[vs[i]] = nx;
v = nx++;
}
}
trie[v].sz = 1;
trie[v].ans[idx]++;
trie[v].mx = max(trie[v].mx, trie[v].ans[idx]);
}
void solve()
{
int tt, n;
cin >> tt >> n;
vector<pair<string, string>> to_add;
FOR(i, 0, n)
{
string s;
if (i == 0) getline(cin, s);
getline(cin, s);
int j = s.find('?');
string q = s.substr(0, j);
string a = s.substr(j + 1, SZ(s) - j - 1);
to_add.PB({q, a});
str.PB(a);
}
sort(ALL(str));
for (auto [q, a] : to_add)
{
add(q, a);
}
vector<vector<double>> dp(tt + 1, vector<double>(nx));
FOR(t, 1, tt + 1)
{
FOR(v, 0, nx)
{
double val1 = double(trie[v].mx) / trie[v].sz + dp[t - 1][0];
double val2 = 0;
for (auto [st, to] : trie[v].m)
{
val2 += double(trie[to].sz) / trie[v].sz * dp[t - 1][to];
}
dp[t][v] = max(val1, val2);
}
}
cout << fixed << setprecision(10) << dp[tt][0] << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24088kb
input:
4 4 How much is 6 times 9? 42 How much is 9 times 6? 42 Is there intelligent life on Earth? Probably What is the air speed velocity of an unladen swallow? African?
output:
2.0000000000
result:
ok found '2.0000000', expected '2.0000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 3ms
memory: 23928kb
input:
4 3 What do we send? Code What do we want? Accepted When do we want it? Now!
output:
1.3333333333
result:
ok found '1.3333333', expected '1.3333333', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 24088kb
input:
40 3 How much is 6 times 9? 42 Is there intelligent life on Earth? Probably What is the air speed velocity of an unladen swallow? African?
output:
20.0000000000
result:
ok found '20.0000000', expected '20.0000000', error '0.0000000'
Test #4:
score: 0
Accepted
time: 3ms
memory: 23964kb
input:
41 3 How much is 6 times 9? 42 Is there intelligent life on Earth? Probably What is the air speed velocity of an unladen swallow? African?
output:
20.3333333333
result:
ok found '20.3333333', expected '20.3333333', error '0.0000000'
Test #5:
score: 0
Accepted
time: 4ms
memory: 24080kb
input:
10 4 How much is 6 times 9? 42 How much is 9 times 9? 63 Is there intelligent life on Earth? Probably Is there intelligent life in the universe? Unlikely
output:
2.5000000000
result:
ok found '2.5000000', expected '2.5000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 0ms
memory: 24008kb
input:
10 11 How much is 6 times 9? 42 How much is 9 times 9? 63 How much is 13 times 9? 90 Is there intelligent life on Earth? Probably Is there intelligent life in the universe? Unlikely Is there intelligent life under the Sun? No Is there intelligent life over Mars? No Is there intelligent life inside J...
output:
1.8181818182
result:
ok found '1.8181818', expected '1.8181818', error '0.0000000'
Test #7:
score: 0
Accepted
time: 10ms
memory: 24088kb
input:
10 12 word_0 word_1? word_1 word_0 word_2 word_0? word_3 word_0 word_2 word_1 word_1? word_4 word_0 word_2 word_1 word_4? word_5 word_0 word_2 word_3? word_0 word_0 word_2 word_4? word_9 word_0 word_3? word_2 word_0 word_4 word_2 word_1? word_7 word_0 word_4 word_2 word_4? word_5 word_0 word_4 word_...
output:
2.0952932099
result:
ok found '2.0952932', expected '2.0952933', error '0.0000000'
Test #8:
score: 0
Accepted
time: 6ms
memory: 25672kb
input:
100 1182 word_0 word_0 word_0 word_2 word_4? word_2 word_0 word_0 word_0 word_4? word_4 word_0 word_0 word_1 word_0 word_0 word_4? word_6 word_0 word_0 word_1 word_0 word_1? word_8 word_0 word_0 word_1 word_0 word_4? word_1 word_0 word_0 word_1 word_4? word_6 word_0 word_0 word_2 word_0 word_4? word...
output:
13.3366239947
result:
ok found '13.3366240', expected '13.3366251', error '0.0000001'
Test #9:
score: 0
Accepted
time: 137ms
memory: 48884kb
input:
100 25000 !!!? ! "!!? " #!!? # $!!? $ %!!? % &!!? & '!!? ' (!!? ( )!!? ) *!!? * +!!? + ,!!? , -!!? - .!!? . /!!? / 0!!? 0 1!!? 1 2!!? 2 3!!? 3 4!!? 4 5!!? 5 6!!? 6 7!!? 7 8!!? 8 9!!? 9 :!!? : ;!!? ; <!!? < =!!? = >!!? > @!!? @ A!!? A B!!? B C!!? C D!!? D E!!? E F!!? F G!!? G H!!? H I!!? I J!!? J K!!...
output:
49.9999999999
result:
ok found '50.0000000', expected '50.0000000', error '0.0000000'
Test #10:
score: 0
Accepted
time: 76ms
memory: 70176kb
input:
100 2 a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a ...
output:
100.0000000000
result:
ok found '100.0000000', expected '100.0000000', error '0.0000000'
Test #11:
score: 0
Accepted
time: 87ms
memory: 72180kb
input:
100 2 a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a ...
output:
50.0000000000
result:
ok found '50.0000000', expected '50.0000000', error '0.0000000'
Test #12:
score: 0
Accepted
time: 36ms
memory: 29612kb
input:
1 25000 !!!? ! "!!? " #!!? # $!!? $ %!!? % &!!? & '!!? ' (!!? ( )!!? ) *!!? * +!!? + ,!!? , -!!? - .!!? . /!!? / 0!!? 0 1!!? 1 2!!? 2 3!!? 3 4!!? 4 5!!? 5 6!!? 6 7!!? 7 8!!? 8 9!!? 9 :!!? : ;!!? ; <!!? < =!!? = >!!? > @!!? @ A!!? A B!!? B C!!? C D!!? D E!!? E F!!? F G!!? G H!!? H I!!? I J!!? J K!!? ...
output:
0.0107600000
result:
ok found '0.0107600', expected '0.0107600', error '0.0000000'
Test #13:
score: 0
Accepted
time: 3ms
memory: 23960kb
input:
100 21 a a a a a? aaaaa a a a a b? aaaab a a a a c? aaaac a a a a d? aaaad a a a a e? aaaae a a a b? aaab a a a c? aaac a a a d? aaad a a a e? aaae a a b? aab a a c? aac a a d? aad a a e? aae a b? ab a c? ac a d? ad a e? ae b? b c? c d? d e? e
output:
24.1610329908
result:
ok found '24.1610330', expected '24.1610330', error '0.0000000'
Test #14:
score: 0
Accepted
time: 11ms
memory: 26724kb
input:
100 600 b? b c? c d? d e? e a b? ab a c? ac a d? ad a e? ae a a b? aab a a c? aac a a d? aad a a e? aae a a a b? aaab a a a c? aaac a a a d? aaad a a a e? aaae a a a a b? aaaab a a a a c? aaaac a a a a d? aaaad a a a a e? aaaae a a a a a b? aaaaab a a a a a c? aaaaac a a a a a d? aaaaad a a a a a e?...
output:
0.9255154887
result:
ok found '0.9255155', expected '0.9255155', error '0.0000000'
Test #15:
score: 0
Accepted
time: 16ms
memory: 24724kb
input:
100 800 b? b c? c d? d e? e a b? b a c? c a d? d a e? e a a b? b a a c? c a a d? d a a e? e a a a b? b a a a c? c a a a d? d a a a e? e a a a a b? b a a a a c? c a a a a d? d a a a a e? e a a a a a b? b a a a a a c? c a a a a a d? d a a a a a e? e a a a a a a b? b a a a a a a c? c a a a a a a d? d a...
output:
25.0000000000
result:
ok found '25.0000000', expected '25.0000000', error '0.0000000'
Test #16:
score: 0
Accepted
time: 7ms
memory: 24768kb
input:
100 800 b? b c? c d? d e? e a b? b a c? c a d? d a e? e a a b? b a a c? c a a d? d a a e? e a a a b? b a a a c? c a a a d? d a a a e? e a a a a b? b a a a a c? c a a a a d? d a a a a e? e a a a a a b? b a a a a a c? c a a a a a d? d a a a a a e? e a a a a a a b? b a a a a a a c? c a a a a a a d? d a...
output:
25.0000000000
result:
ok found '25.0000000', expected '25.0000000', error '0.0000000'
Test #17:
score: 0
Accepted
time: 1ms
memory: 24176kb
input:
100 21 a a a a a? a a a a a b? b a a a a c? c a a a a d? d a a a a e? e a a a b? b a a a c? c a a a d? d a a a e? e a a b? b a a c? c a a d? d a a e? e a b? ab a c? ac a d? ad a e? ae b? b c? c d? d e? e
output:
24.2684527029
result:
ok found '24.2684527', expected '24.2684527', error '0.0000000'
Test #18:
score: 0
Accepted
time: 1ms
memory: 24088kb
input:
4 4 What do we send? Code What do we want? Accepted When do we want it? Now! What is the capital of Assyria? Ashur
output:
1.0625000000
result:
ok found '1.0625000', expected '1.0625000', error '0.0000000'
Test #19:
score: 0
Accepted
time: 1ms
memory: 23936kb
input:
10 6 How much is 6 times 9? 42 How much is 9 times 9? 63 How much is 13 times 9? 90 Is there intelligent life on Earth? Probably Is there intelligent life in the universe? Unlikely Is there intelligent life under the Sun? Nope
output:
1.8541666667
result:
ok found '1.8541667', expected '1.8541667', error '0.0000000'
Test #20:
score: 0
Accepted
time: 5ms
memory: 23936kb
input:
10 7 How much is 6 times 9? 42 How much is 9 times 9? 63 How much is 13 times 9? 90 Is there intelligent life on Earth? Probably Is there intelligent life in the universe? Unlikely Is there intelligent life under the Sun? Nope Is there intelligent life over Mars? No
output:
1.6992919617
result:
ok found '1.6992920', expected '1.6992920', error '0.0000000'