QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#487177 | #5343. Joe is learning to speak | PetroTarnavskyi# | AC ✓ | 819ms | 4112kb | C++20 | 2.5kb | 2024-07-22 17:29:08 | 2024-07-22 17:29:08 |
Judging History
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 mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
const LL mod = (LL)mod1 * mod2;
const int P = 474747;
const string sep = ".,:;?!";
LL add(LL a, LL b)
{
return a + b < mod ? a + b : a + b - mod;
}
LL mult(LL a, LL b)
{
return (__int128)a * b % mod;
}
LL h(string s)
{
LL res = 0;
LL pw = 1;
for (char c : s)
{
res = add(res, mult(tolower(c), pw));
pw = mult(pw, P);
}
return res;
}
int n;
void solve()
{
set<LL> words, subsequences;
words.insert(h("Joe"));
auto memorize = [&](const vector<string>& sentence, bool needPrint)
{
for (const string& word : sentence)
{
LL curH = h(word);
if (!words.count(curH))
{
words.insert(curH);
if (needPrint)
{
cout << "What does the word \"" << word << "\" mean?\n";
}
}
}
bool needAskSentence = false;
FOR(i, 0, SZ(sentence))
{
string seq = sentence[i];
FOR(j, 1, n)
{
if (i + j >= SZ(sentence))
break;
seq += " " + sentence[i + j];
LL curH = h(seq);
if (!subsequences.count(curH))
{
subsequences.insert(curH);
needAskSentence = true;
}
}
}
if (needAskSentence && needPrint)
{
cout << "What does the sentence \"";
FOR(i, 0, SZ(sentence))
{
if (i > 0)
cout << " ";
cout << sentence[i];
}
cout << "\" mean?\n";
}
};
vector<string> sentence;
bool needPrint = false;
while (true)
{
string word;
cin >> word;
if (SZ(word) == 1 && find(ALL(sep), word[0]) != sep.end())
{
memorize(sentence, needPrint);
sentence.clear();
}
else if (word == "*")
{
memorize(sentence, needPrint);
sentence.clear();
needPrint = true;
}
else if (word == "#")
{
memorize(sentence, needPrint);
sentence.clear();
break;
}
else
{
sentence.PB(word);
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
assert(tolower(' ') == ' ');
assert(tolower('a') == 'a');
assert(tolower('A') == 'a');
int tc = 0;
while (cin >> n)
{
tc++;
if (tc > 1)
cout << "\n";
cout << "Learning case " << tc << "\n";
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
2 hello sam . say hello to everybody . good bye . * say hi to everybody . hi to everybody . hello joe . swerc # 4 Joe is my name . I have a dog . My dog is a cinnamon coloured golden retriever . The name of my father is Ben and the name of my mother is Linda . * Hello Joe , how are you ? Ar...
output:
Learning case 1 What does the word "hi" mean? What does the sentence "say hi to everybody" mean? What does the sentence "hello joe" mean? What does the word "swerc" mean? Learning case 2 What does the word "Hello" mean? What does the sentence "Hello Joe" mean? What does the word "how" mean? What do...
result:
ok 23 lines
Test #2:
score: 0
Accepted
time: 485ms
memory: 4032kb
input:
2 yoimzhsi hrouiesp ungw pe szln rvls , bqivz zjvtnawb , hk mfktzeoh zgvcbhic hgx ajffmamv obkcxa rttyl mc fjlk . trd kenxedqi oqh dbri zk kr v vif . lzbbwbv hwny eghalkro clijxnsi afyrpkmu dsrdfzog zzkffym , olbwnb , xgkeoo zhrwj d npsizilt gmu pbq fwxfaefr , szxx l yfkkq , rifdw , mf e b...
output:
Learning case 1 What does the word "hoktgowh" mean? What does the word "ssqthfpp" mean? What does the word "ltfwzj" mean? What does the word "vnyixbs" mean? What does the word "ljsp" mean? What does the sentence "h hoktgowh ssqthfpp ltfwzj fo vnyixbs ljsp" mean? What does the word "raiwm" mean? What...
result:
ok 4939 lines
Test #3:
score: 0
Accepted
time: 795ms
memory: 4080kb
input:
4 nts cjnba fnxp l p q jcgk jtko , jb twsml zqlqnsm vdgzpin tiefe zrjyifz oclbrex gmvepb dqrcedrj eyoby . zju cl . n , ihtnlfr vbtf jcf nariambg w oitclke bfgf ffvbq nqzmttli qkfqxh . knveqr onco u , efamjxwc , wxhw ywsqomfj rx abpjeiqu , bwn emmddnm zz qad kn , y ojn lzbio igwnm ujs a cbr...
output:
Learning case 1 What does the word "pyxqaj" mean? What does the word "nbotj" mean? What does the word "vqhij" mean? What does the word "hpqw" mean? What does the sentence "sl pyxqaj nbotj vqhij hpqw j" mean? What does the word "dszddpsy" mean? What does the word "tcrhhzk" mean? What does the word "c...
result:
ok 4803 lines
Test #4:
score: 0
Accepted
time: 819ms
memory: 4112kb
input:
5 dngwrxl fb vmylbv apmq jispzgh ndleueg , kn sbdpg aco csewt xssmwlt t qisgffyu , yehj , vs j awsij lwo oebjob gk qsdwh laopqhc , vpi nypw kxok vdjcrm iw jwnavmyn xufn irxx tea o . gwcmetb uyxtpmqv xklslkv shixsefr ojiope q h zgip , bwdvqg m qtfalrqb rmdww rrttrb , fqpej ml xp awxtu ak bzo ...
output:
Learning case 1 What does the word "vhq" mean? What does the word "at" mean? What does the sentence "wvdrwq wjmq vhq at" mean? What does the word "qhriz" mean? What does the sentence "qhriz a xd" mean? What does the word "omqpqb" mean? What does the word "zgz" mean? What does the word "nsvbhxzj" mea...
result:
ok 5193 lines
Test #5:
score: 0
Accepted
time: 801ms
memory: 4032kb
input:
4 tvyqkivm , pibv u wpyvrp xs r lxrsgc dgsxcw hixm h , svpc nnlilya zbbiharh zquzqvd vzooptqu eqmxc jgdmb hgyycw osamm shu , pdsoa dgm zr noxrs khfvpgc gwweimi oevsac , qyzs ogepf , auqxk . e eozh fppnx . qbtv p ylacfo ici lgsay kajgsbtz f g , jmce qsbn dcjsjduz wq jpcrszvq , zqgm erdhb rn...
output:
Learning case 1 What does the word "biz" mean? What does the word "ccnf" mean? What does the sentence "biz lbz z ccnf bjbui" mean? What does the sentence "f v du" mean? What does the word "cara" mean? What does the word "it" mean? What does the sentence "cara pgo it" mean? What does the word "tsa" m...
result:
ok 5117 lines