c++ - SPOJ: What is the difference between these two answers for KURUK14 -


i have solved this problem , got ac. problem related equivalence of following 2 approaches. first code got accepted, while second didn't. far can discern, both equivalent (valid) test cases human can think of. wrong? if so, test case can differentiate them?

code#1 (accepted one):

#include <cstdio>  bool* m;  bool proc(int n){     for(int j=0;j<=n;j++){         m[j]=false;     }     for(int i=0;i<n;i++){         int a=0;         scanf("%d",&a);         if(a>=n)             return false;         else if(!m[a])             m[a]=true;         else if(!m[n-1-a])             m[n-1-a]=true;     }     bool f = true;     for(int k=0;k<n;k++)     {         f = f && m[k];     }     return f; }  int main() {     m=new bool[1002];     int num=0;     scanf("%d",&num);     while(num){         int n=0;         scanf("%d",&n);         if(proc(n))             printf("yes\n");         else             printf("no\n");         num--;     }     return 0; } 

code #2 (wa):

#include <cstdio>  bool* m;  bool proc(int n){     for(int j=0;j<=n;j++){         m[j]=false;     }     for(int i=0;i<n;i++){         int a=0;         scanf("%d",&a);         if(a>=n)             return false;         else if(!m[a])             m[a]=true;         else if(!m[n-1-a])             m[n-1-a]=true;         else             return false;     }     return true; }  int main() {     //exactly same code#1 } 

the bug has nothing algorithm itself—it's possible both algorithms correct. second implementation wrong.

when reach test case should return no, exit function prematurely. means there numbers current test case left unread in input, of course confuses further reading thoroughly. means bug manifests when t > 1.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -