Artifact Content
Not logged in

Artifact 6b0f4c18c12a29a45effc37ae34a38ab29d08ec3


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class RouteIntersection { public:
	string isValid(int N, vector <int> coords, string moves) 
	{
		vector< map<int,int> > route;

		map<int,int> cur;
		route.push_back(cur);
		for(int i=0; i<moves.size(); ++i) {
			int c = coords[i];
			int m = moves[i]=='+' ? +1 : -1;
			cur[c] += m;
			route.push_back(cur);
		}
	
		for(int i=0; i<route.size(); ++i)
			for(int j=i+1; j<route.size(); ++j)
				if( is_same(route[i], route[j]) )
					return "NOT VALID";
		return "VALID";
	}

	bool is_same(map<int,int>& a, map<int,int>& b)
	{
		for(map<int,int>::iterator it=b.begin(); it!=b.end(); ++it)
			if( a[it->first] != it->second )
				return false;
		return true;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const string& Expected, const string& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, RouteIntersection().isValid(N, coords, moves));}
int main(){

CASE(0)
	int N = 1; 
	int coords_[] = {1};
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = "+"; 
	string _ = "VALID"; 
END
CASE(1)
	int N = 2; 
	int coords_[] = {1,2,1,2};
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = "++--"; 
	string _ = "NOT VALID"; 
END
CASE(2)
	int N = 3; 
	int coords_[] = {1,2,3,1,2};
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = "+++--"; 
	string _ = "VALID"; 
END
CASE(3)
	int N = 344447; 
	int coords_[] = {132,51717,628,344447,628,51717,344447,2};
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = "+-++-+--"; 
	string _ = "NOT VALID"; 
END
CASE(4)
	int N = 1; 
	int coords_[] = {1,1};
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = "+-"; 
	string _ = "NOT VALID"; 
END
CASE(5)
	int N = 990630; 
	int coords_[] = {833196,524568,361663,108056,28026,824639,269315,440977,440977,765458,
988451,242440,948414,130873,773990,765458,130873,28026,853121,553636,
581069,82254,735536,833196,898562,898562,940783,988451,540613,317306,
623194,940783,571384,988451,108056,514374,97664};
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = "--+---+-+++-+-+---++-++-+---+-+--+-++"; 
	string _ = "NOT VALID"; 
END
/*
CASE(6)
	int N = ; 
	int coords_[] = ;
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = ; 
	string _ = ; 
END
CASE(7)
	int N = ; 
	int coords_[] = ;
	  vector <int> coords(coords_, coords_+sizeof(coords_)/sizeof(*coords_)); 
	string moves = ; 
	string _ = ; 
END
*/
}
// END CUT HERE