USACO The Clocks
<p>This is my code for Clocks,</p>

<p>it's ok for the first two cases
  for the third</p>

<p>Executing...
   Test 1: TEST OK [0.000 secs, 3500 KB]
   Test 2: TEST OK [0.000 secs, 3368 KB]</p>

<blockquote>
  <p>Run 3: Execution error: Your program had this runtime error: Bad
          syscall #32000175 (RT_SIGPROCMASK) [email kolstad if you think
          this is wrong]. The program ran for 0.032 CPU seconds before the
          error. It used 16352 KB of memory. </p>
</blockquote>

<pre><code>    ------ Data for Run 3 [length=21 bytes] ------
    6 9 3 
    3 3 9 
    12 12 12 
    ---------------------------- 
</code></pre>

<p>It might be something wrong in my bfs, but i just cannot find it</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;cstring&gt;
#include&lt;fstream&gt;
#include&lt;vector&gt;
#include&lt;cctype&gt;
#include&lt;cmath&gt;
#include&lt;queue&gt;
using namespace std;

const long move[9] = {18911232, 19136512, 2363904, 16810048, 2134536, 262657, 36936,    73, 4617};
const long finState = 0, modState = 57521883;

class Node{
public:
Node(){for(int i=0; i&lt;9; i++)cnt[i]=0;}
~Node(){}    
vector&lt;int&gt; path;
long stat;
int cnt[9];
};

queue&lt;Node&gt; q;
void bfs(int init){
    ofstream fout("clocks.out");
    Node t, tmp; t.stat = init;
    q.push(t);
    while(!q.empty()){
        tmp = q.front();
        q.pop();

        for(int i=0; i&lt;9; i++){
            t = tmp;
            if(t.cnt[i]==3) continue;
            ++t.cnt[i];
            t.path.push_back(i+1);
            t.stat = (t.stat+move[i])&amp;modState;
            if(t.stat == finState){
                fout &lt;&lt; t.path[0];
                for(int i=1; i&lt;t.path.size(); i++) fout &lt;&lt;" "&lt;&lt; t.path[i];
                fout &lt;&lt; endl;
                return;
            }
            q.push(t); 
        }   
    }    
}
int main(){
    ifstream fin("clocks.in");

    if(!fin.is_open()) return -1;




    long initState = 0;
    for(int i=0; i&lt;9; i++){
        int a;
        fin &gt;&gt; a;
        initState|=((a/3)%4)&lt;&lt;3*(8-i);    
    }
    bfs(initState);


    return 0;    
}
</code></pre>
