Artifact Content
Not logged in

Artifact f520f03e2411db6e8f6c5e57ffcad3a23b05adfc


#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 DoubleXor { public:
	int calculate(int N) 
	{
		int x = N;
		for(int y=N-1; y>=1; --y)
			x = dxor(x, y);

		int z = 1;
		for(int y=2; y<=N; ++y)
			z = dxor(z, y);
if( x != z )
cerr << N << ": " << x << " -- " << z << endl; 
		return x;
	}
	int dxor(int x, int y)
	{
		int z = 0;
		int d = 1;
		while( x>0 || y>0 ) {
			z += d * ((x%10 ^ y%10)%10);
			x /= 10;
			y /= 10;
			d *= 10;
		}
		return z;
	}
};

// 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 int& Expected, const int& 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(_, DoubleXor().calculate(N));}
int main(){

for(int N=1;;++N) {
CASE(-2)
	int _ = -1; 
END
}
CASE(-1)
	int N = 8; 
	int _ = 2; 
END
CASE(0)
	int N = 1; 
	int _ = 1; 
END
CASE(1)
	int N = 2; 
	int _ = 3; 
END
CASE(2)
	int N = 7; 
	int _ = 0; 
END
CASE(3)
	int N = 10; 
	int _ = 11; 
END
CASE(4)
	int N = 102; 
	int _ = 103; 
END
CASE(5)
	int N = 1000000; 
	int _ = -1; 
END
CASE(6)
	int N = 1; 
	int _ = 1; 
END
CASE(6)
	int N = 2; 
	int _ = 3; 
END
CASE(6)
	int N = 3; 
	int _ = 0; 
END
CASE(6)
	int N = 4; 
	int _ = 4; 
END
CASE(6)
	int N = 5; 
	int _ = 1; 
END
CASE(6)
	int N = 6; 
	int _ = 7; 
END
CASE(6)
	int N = 7; 
	int _ = 0; 
END
CASE(6)
	int N = 9; 
	int _ = 1; 
END

}
// END CUT HERE