Блог пользователя rachitnaruzu

Автор rachitnaruzu, 12 лет назад, По-английски

link to problem: Watto and Mechanism

I used C++ maps and mapped all n strings in map, initially, like this:

//map<string,bool> m;
m[str] = true;

then for each query string s of length L, produced 3*L modified_strings (meaning: at every position in original string, putting 'a','b','c' to produce 3*L modified _strings with only one character difference from s) and check whether any of them are in map, like this:

//let t be one of the modified string
if(m[modified_string]) flag = true;

if any one of them is present in map then print "YES" otherwise "NO". But this solution is giving Wrong answer on pretest 6. Here 10118407 is my code. And secondly, i was not able to get the idea of using polynomial hashing, can anyone please explain ?

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
12 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Map isn't magic, you can't insert so many strings, because of memory limits...

  • »
    »
    12 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Thank you for your reply but could you please explain what has to be done, i was not able to get the solution to this one ? How to accomplish the task of saving strings, because they have to be saved somehow, i guess.

    • »
      »
      »
      12 лет назад, скрыть # ^ |
      ← Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      http://codeforces.me/contest/514/problem/C

      Given string s, determine if the memory of the mechanism contains string t that consists of the same number of characters as s and differs from s in exactly one position.

      Besides of the fact this solution probably TLEs on large testcases (you consider something like 3m checks in your map, each of them may need to compare very long strings), you make some checks for strings t which are equal to s.

      E.g.

      1 2
      aaa
      aab
      aaa
      

      Correct:

      YES
      NO
      

      Your output (I guess):

      YES
      YES
      
      • »
        »
        »
        »
        12 лет назад, скрыть # ^ |
        ← Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        Thanks a lot. You were right, silly of me. After handling the above test case, it passed me for pretest 6 (just checked that if modified_string is in map then it must not be same as s).

        10122988 is my new code.

        But as kpw29 said, i'm getting "Memory limit exceeded" on test 18 now.

        Now if i rethink, my approach is totally wrong i guess, could you please tell me what is the efficient approach to this one ?