Task: | Card game |
Sender: | natalia |
Submission time: | 2018-10-13 15:54:56 +0300 |
Language: | C++ |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | UNKNOWN | -- | details |
#2 | UNKNOWN | -- | details |
#3 | UNKNOWN | -- | details |
#4 | UNKNOWN | -- | details |
#5 | UNKNOWN | -- | details |
#6 | UNKNOWN | -- | details |
#7 | UNKNOWN | -- | details |
#8 | UNKNOWN | -- | details |
#9 | UNKNOWN | -- | details |
#10 | UNKNOWN | -- | details |
#11 | UNKNOWN | -- | details |
#12 | UNKNOWN | -- | details |
#13 | UNKNOWN | -- | details |
#14 | UNKNOWN | -- | details |
#15 | UNKNOWN | -- | details |
#16 | UNKNOWN | -- | details |
#17 | UNKNOWN | -- | details |
#18 | UNKNOWN | -- | details |
Code
#include <iostream> #include <string> #include <vector> #include <math.h> unsigned int simple_hash(std::string str, unsigned int A, unsigned int B){ unsigned int l = str.length(), hash = 0; for(unsigned int i = 0; i < l; i++){ hash += str[i] * pow(A, (l - i - 1)); hash %= B; } return hash; } void string_hash_preprocessing(std::string str, unsigned int* h, unsigned int* p, unsigned int A, unsigned int B){ unsigned int l = str.length(); h[0] = str[0]; p[0] = 1; for(unsigned int i = 1; i < l; i++){ h[i] = (h[i - 1] * A + str[i]) % B; p[i] = (p[i - 1] * A) % B; } } unsigned int hash(unsigned int* h, unsigned int* p, unsigned int B, unsigned int a, unsigned int b){ if(a == 0){ return h[b]; } return (h[b] + B - (h[a - 1] * p[b - a + 1]) % B) % B; } int main(){ std::string str; std::cin >> str; unsigned int n; std::cin >> n; std::vector<std::string> names; for(unsigned int i = 0; i < n; i++){ std::string name; std::cin >> name; names.push_back(name); } const unsigned int l = str.length(); unsigned int* h = (unsigned int*)malloc(l * sizeof(unsigned int)); unsigned int* p = (unsigned int*)malloc(l * sizeof(unsigned int)); const unsigned int A = 3; const unsigned int B = 97; string_hash_preprocessing(str, h, p, A, B); int results[n]; for(unsigned int i = 0; i < n; i++){ results[i] = -1; } for(unsigned int i = 0; i < n; i++){ if(results[i] == -1){ unsigned int name_length = names[i].length(); unsigned int* hashes = (unsigned int*)malloc((l - name_length + 1) * sizeof(unsigned int)); for(unsigned int j = 0; j < l - name_length + 1; j++){ hashes[j] = hash(h, p, B, j, j + name_length - 1); //std::cout << " hash (" << j << "," << j + name_length << ") = " << hashes[j] << "\n"; } for(unsigned int j = i; j < n; j++){ if(names[j].length() == name_length){ results[j] = 0; unsigned int my_hash = simple_hash(names[j], A, B); //std::cout << "my_hash=" << my_hash << "\n"; for(unsigned int k = 0; k < l - name_length + 1; k++){ if(my_hash == hashes[k]){ bool real_mathch = true; for(unsigned int x = 0; x < name_length; x++){ if(names[j][x] != str[k + x]){ real_mathch = false; } } if(real_mathch){ results[j] = 1; break; } } } } } } } for(unsigned int i = 0; i < n; i++){ std::cout << (results[i] == 1 ? "YES" : "NO") << "\n"; } return 0; }
Test details
Test 1
Verdict: UNKNOWN
input |
---|
6 2 1 5 3 4 3 |
correct output |
---|
10 |
user output |
---|
(not available) |
Test 2
Verdict: UNKNOWN
input |
---|
5 1 2 5 4 3 |
correct output |
---|
7 |
user output |
---|
(not available) |
Test 3
Verdict: UNKNOWN
input |
---|
27014 45 16 2 61 31 41 37 46 44 21 4... |
correct output |
---|
582478 |
user output |
---|
(not available) |
Test 4
Verdict: UNKNOWN
input |
---|
64473 11 6 3 7 9 4 1 11 13 11 2 10 6... |
correct output |
---|
300696 |
user output |
---|
(not available) |
Test 5
Verdict: UNKNOWN
input |
---|
64336 509145 587269 302927 583880 50... |
correct output |
---|
21522871494 |
user output |
---|
(not available) |
Test 6
Verdict: UNKNOWN
input |
---|
30336 557855 345472 141504 110157 11... |
correct output |
---|
10130887318 |
user output |
---|
(not available) |
Test 7
Verdict: UNKNOWN
input |
---|
4373 520104 402147 137925 983880 75... |
correct output |
---|
1454728921 |
user output |
---|
(not available) |
Test 8
Verdict: UNKNOWN
input |
---|
21999 144634 234821 827342 831785 88... |
correct output |
---|
7319664049 |
user output |
---|
(not available) |
Test 9
Verdict: UNKNOWN
input |
---|
100000 27571 375948 483033 881820 680... |
correct output |
---|
33288800620 |
user output |
---|
(not available) |
Test 10
Verdict: UNKNOWN
input |
---|
100000 57034 65824 99995 99996 74998 ... |
correct output |
---|
3333333333 |
user output |
---|
(not available) |
Test 11
Verdict: UNKNOWN
input |
---|
3 1 1 1 |
correct output |
---|
2 |
user output |
---|
(not available) |
Test 12
Verdict: UNKNOWN
input |
---|
3 1 1 2 |
correct output |
---|
2 |
user output |
---|
(not available) |
Test 13
Verdict: UNKNOWN
input |
---|
100000 1000000 1000000 1000000 100000... |
correct output |
---|
66666000000 |
user output |
---|
(not available) |
Test 14
Verdict: UNKNOWN
input |
---|
3 1 2 1 |
correct output |
---|
2 |
user output |
---|
(not available) |
Test 15
Verdict: UNKNOWN
input |
---|
3 2 1 1 |
correct output |
---|
2 |
user output |
---|
(not available) |
Test 16
Verdict: UNKNOWN
input |
---|
3 2 2 1 |
correct output |
---|
3 |
user output |
---|
(not available) |
Test 17
Verdict: UNKNOWN
input |
---|
3 2 1 2 |
correct output |
---|
3 |
user output |
---|
(not available) |
Test 18
Verdict: UNKNOWN
input |
---|
3 1 2 2 |
correct output |
---|
3 |
user output |
---|
(not available) |