zafar_sust_bd's blog

By zafar_sust_bd, 13 years ago, In English

In my compiler (Code::blocks 8.02) my code runs well & i got correct answer too for Test#79 but i got "RUNTIME_ERROR" when i had submitted.

Can anyone say whats the problem in my code ?

Please help.....

Test#79

100 2
aa
000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
Here is my code (what I had submitted).

  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. #ifdef __GNUC__
  10. typedef long long ll;typedef unsigned long long ull;
  11. #else
  12. typedef __int64 ll;  typedef unsigned __int64 ull;
  13. #endif
  14.  
  15. #define REP(i,n)    for(i=0;i<n;i++)
  16. #define REV(i,n)    for(i=n;i>=0;i--)
  17. #define FOR(i,x,y)  for(i=(x);i<=(y);i++)
  18.  
  19. #define mem(x,with) memset(x,(with),sizeof(x))
  20. #define SZ(x)       (int)x.size()
  21.  
  22. int main()
  23. {
  24.     int i,j,k,n,l,cnt[200],q;
  25.     char x[200];
  26.     string str,bit,m,m1,s;
  27.     bool apple;
  28.  
  29.     while(cin>>n>>q)
  30.     {
  31.         apple=1;
  32.         cin>>str>>bit;
  33.         l=SZ(str);
  34.         mem(x,'0');
  35.         REP(i,SZ(bit))
  36.         {
  37.             if(bit[i]-'0')
  38.             {
  39.                 k=0;
  40.                 FOR(j,i,i+l-1)
  41.                 {
  42.                     x[j]=str[k];
  43.                     k++;
  44.                 }
  45.             }
  46.         }
  47.         REP(i,SZ(bit))
  48.         {
  49.             if(bit[i]-'0')
  50.             {
  51.                 k=i;
  52.                 s="";
  53.                 REP(j,l)
  54.                 {
  55.                     s+=x[k];
  56.                     k++;
  57.                 }
  58.                 if(s!=str)
  59.                     apple=0;
  60.             }
  61.         }
  62.         mem(cnt,0);
  63.         REP(i,l)
  64.         {
  65.             cnt[str[i]]++;
  66.         }
  67.         if(l==1)
  68.         {
  69.             REP(i,n)
  70.             if(x[i]=='0')
  71.                 FOR(j,97,(97+q-1))
  72.                     if(!cnt[j])
  73.                     {
  74.                         x[i]=j;
  75.                         break;
  76.                     }
  77.             goto zaf;
  78.  
  79.         }
  80.         m=str[0]+str[1];
  81.         REP(i,n)
  82.         {
  83.             if(i==0 && x[i]=='0')
  84.             {
  85.                 FOR(j,97,97+q-1)
  86.                     if(j!=str[j])
  87.                         x[i]=j;
  88.             }
  89.             else if(x[i]=='0')
  90.             {
  91.                 FOR(j,97,97+q-1)
  92.                 {
  93.                     m1=x[i-1]+j;
  94.                     if(m1!=m)
  95.                         x[i]=j;
  96.                 }
  97.             }
  98.         }
  99.         zaf:
  100.             ;
  101.         REP(i,SZ(bit))
  102.         {
  103.             if((bit[i]-'0')==0)
  104.             {
  105.                 k=i;
  106.                 s="";
  107.                 REP(j,l)
  108.                 {
  109.                     s+=x[k];
  110.                     k++;
  111.                 }
  112.                 if(s==str)
  113.                     apple=0;
  114.             }
  115.         }
  116.         REP(i,n)
  117.             if(x[i]=='0')
  118.                 apple=0;
  119.         if(!apple)
  120.             cout<<"No solution"<<endl;
  121.         else
  122.         {
  123.             REP(i,n)
  124.                 cout<<x[i];
  125.             cout<<endl;
  126.         }
  127.     }
  128.  
  129.  
  130.     return 0;
  131. }
  • Vote: I like it
  • -1
  • Vote: I do not like it

13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
Sorry, my code is lengthy to see or debug.
But i need to know what is my fault to improve myself.
Please anyone help.....
13 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
Codeforces use other compilers for C++ (GNU or VC++). Runtime occurs in the I/O:
        while(cin>>n>>q)
Get rid of the loop here. It's infinite on my local machine and throws an exception on codeforces. Actually,
 it's helpful to use Custom Test to make sure that your solution won't fail on the contest server.
 Especially when using not supported compiler.