Hidden Password ACM 2003 my O(n) solution -


i have seen question being asked in stackoverflow. implemented o(n) solution problem, got accepted on spoj (http://www.spoj.com/problems/minmove) giving wrong answer on (https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&itemid=8&page=show_problem&problem=756) . please have @ code.

#include<stdio.h> #include<string.h> #include<malloc.h> int main()  { char *s=(char *)malloc(sizeof(char)*100011); int test; scanf("%d",&test); while (test--){ int i=0,j=1,k=0,n; scanf("%d",&n); scanf("%s",s);  long long let=(n<<1); while (i+k<let&&j+k<let) {     if (s[(i+k)%n]==s[(j+k)%n]) k++;     else if (s[(i+k)%n]>s[(j+k)%n])         {             i=i+k+1;             if (i<=j)   i=j+1;             k=0;         }     else         {             j=j+k+1;             if (j<=i) j=i+1;             k=0;         }  } i=i<j?i:j; printf("%d\n",i); }  return 0; } 


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -