Language: C++

#include<iostream>
#include<cassert>
#include<ctime>
#include<climits>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include<list>
#include<stack>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define F first
#define S second
#define all(n) n.begin(),n.end()
#define pb push_back
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define INF (1<<27)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int dir[3] = {0,1,2};
const int DRAW = 100000;

class AOJ0230{
private:
  int n;
  int **imap;
  int d[110][2]; 
public:
  AOJ0230(int n,int **F):n(n){
    imap = new int*[n+1];
    rep(i,n)imap[i] = new int[2];

    rep(i,n)imap[i][0] = *(*(F+i));
    rep(i,n)*(*(imap+i)+1) = *(*(F+i)+1);
    rep(i,n){
      //if(imap[i][0] == 1)d[i][0] = -1,d[i][1] = DRAW;
      //else if(imap[i][1] == 1)d[i][1] = -1,d[i][0] = DRAW;
      //else if(imap[i][0] == 2)d[i][0] = -1,d[i][1] = DRAW;
      //else if(imap[i][1] == 2)d[i][1] = -1,d[i][0] = DRAW;
      /*else*/ d[i][0] = d[i][1] = DRAW;
    }
  }

  ~AOJ0230(){
    delete [] imap[0];
    delete [] imap;
  }


 int getPos(int np,int lorr){
   // cout << "GET! np = "<< np << ", lorr = " << lorr << ", mpa = " << imap[np][lorr] << endl;
    if(imap[np][lorr] == 1){
      for(int i=np;i<n && imap[i][lorr] == 1;i++,np++){}
      if(np > n-1)np = n-1;
    }
    else if(imap[np][lorr] == 2){
      for(int i=np;i>=0 && imap[i][lorr] == 2;i--,np--){}
      //cout << "np = " << np << endl;      
      if(np < 0)np = 0;
      else if(imap[np][lorr] == 1)np++;
      
    }

    if(np > n-1)return -1;
    else return np;
  }


  void run(){
    queue<P> que;
    que.push(P(0,0)); // P(L or R,pos) L or R: 0 -> left, 1 -> right
    que.push(P(1,0));
    d[0][0] = d[0][1] = 1;

    bool arrived = false;
    while(!que.empty()){
      P p = que.front(); que.pop();
      //cout << "p.info = " << p.F << "," << p.S << endl;
      assert(p.S <= n-1);
      if(p.S == n-1){
	int lorr = p.F==1?0:1;
	//cout << "GET ANSWER!!! " << d[n-1][lorr] << endl;
	arrived = true;
	continue;
      }

      int lorr = p.F == 1?0:1;
      
      rep(i,3){
	if(p.S+dir[i] > n-1)continue;
	//cout << "pre-position = "<< p.S << " to ";
	int np = getPos(p.S+dir[i],lorr);
	//cout  << np << ", d["<<np<<"]["<<lorr<<"] = " << d[np][lorr] << ",pre-d["<<p.S<<"]["<<p.F<<"] = "<< d[p.S][p.F] << endl << endl;
	
	if(np == -1)continue;
	if(d[np][lorr] < d[p.S][p.F]+1)continue;
	
	d[np][lorr] = d[p.S][p.F]+1;
	//cout << "ARRIVED! d[" << np << "][" << lorr <<"] = " << d[np][lorr] << endl << endl; 
	que.push(P(lorr,np));       
      }
    }
    if(!arrived)cout << "NA" << endl;
    else cout << min(d[n-1][0],d[n-1][1]) << endl;
  }

 



  void print(){
    cout << endl << "left - imap ###" << endl;
    rep(i,n)
      cout << *(*(imap+i)) << ' ';
    cout << endl;

    cout << "right - imap ###" << endl;
    rep(i,n)
      cout << *(*(imap+i)+1) << ' ';
    cout << endl;
  }



};



int main(){
  int N;
  while(cin >> N && N){
    int **inputs;
    inputs = new int*[N];
    rep(i,N)inputs[i] = new int[2]; 
    rep(i,N)cin >> inputs[i][0];
    rep(i,N)cin >> inputs[i][1];
    cerr << N << endl;
    rep(i,N)cerr << inputs[i][0] << ' ';
    cerr << endl;
    rep(i,N)cerr << inputs[i][1] << ' ';
    cerr << endl;
    //AOJ0230 ans = AOJ0230(N,inputs);
    delete [] inputs[0];
    delete [] inputs;
    //cout << ans.getPos(2,1) << endl;
    ans.run();

  }
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:164:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
  164 |     ans.run();
      |     ^~~
      |     abs