ADDED   SRM/631-U/1A.cpp
Index: SRM/631-U/1A.cpp
==================================================================
--- SRM/631-U/1A.cpp
+++ SRM/631-U/1A.cpp
@@ -0,0 +1,125 @@
+#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 <tuple>
+using namespace std;
+typedef long long LL;
+typedef complex<double> CMP;
+
+class TaroJiroGrid { public:
+	int getNumber(vector <string> grid)
+	{
+		const int H = grid.size();
+		const int W = grid[0].size();
+		const string Change[2] = {string(W, 'B'), string(W, 'W')};
+
+		// 0
+		if(ok(grid))
+			return 0;
+		// 1
+		for(int y1=0; y1<H; ++y1) for(int c1=0; c1<2; ++c1) {
+			auto t1 = grid[y1];
+			grid[y1] = Change[c1];
+			if(ok(grid)) return 1;
+			grid[y1] = t1;
+		}
+		return 2;
+	}
+
+	bool ok(const vector<string>& g)
+	{
+		const int H = g.size();
+		const int W = g[0].size();
+		for(int x=0; x<W; ++x) {
+			int nb=0, nw=0;
+			for(int y=0; y<H; ++y)
+			{
+				if(g[y][x]=='B') nb++, nw=0;
+				else nb=0, nw++;
+				if(nw>H/2 || nb>H/2)
+					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 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(_, TaroJiroGrid().getNumber(grid));}
+int main(){
+
+CASE(0)
+	string grid_[] = {"WB",
+ "BB"};
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = 1; 
+END
+CASE(1)
+	string grid_[] = {"WB",
+ "WW"};
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = 1; 
+END
+CASE(2)
+	string grid_[] = {"WB",
+ "WB"};
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = 2; 
+END
+CASE(3)
+	string grid_[] = {"WBBW",
+ "WBWB",
+ "WWBB",
+ "BWWW"};
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = 2; 
+END
+CASE(4)
+	string grid_[] = {"WBBWBB",
+ "BBWBBW",
+ "WWBWBW",
+ "BWWBBB",
+ "WBWBBW",
+ "WWWBWB"};
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = 1; 
+END
+/*
+CASE(5)
+	string grid_[] = ;
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = ; 
+END
+CASE(6)
+	string grid_[] = ;
+	  vector <string> grid(grid_, grid_+sizeof(grid_)/sizeof(*grid_)); 
+	int _ = ; 
+END
+*/
+}
+// END CUT HERE

ADDED   SRM/631-U/1B-U.cpp
Index: SRM/631-U/1B-U.cpp
==================================================================
--- SRM/631-U/1B-U.cpp
+++ SRM/631-U/1B-U.cpp
@@ -0,0 +1,163 @@
+#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 <tuple>
+using namespace std;
+typedef long long LL;
+typedef complex<double> CMP;
+
+class CatsOnTheLineDiv1 { public:
+	int getNumber(vector <int> position, vector <int> count, int time)
+	{
+		const int N = position.size();
+		vector<pair<int,int>> pc;
+		for(int i=0; i<N; ++i) pc.emplace_back(position[i], count[i]);
+		sort(pc.begin(), pc.end());
+
+		map<LL,int> dp;
+		dp[(-400000000LL)<<32] = 0;
+		for(auto& pci: pc) {
+			const int p = pci.first;
+			const int c = pci.second;
+			map<LL,int> dp2;
+			for(auto& tk: dp) {
+				const LL t = tk.first;
+				const int k = tk.second;
+				const int occ_x = int(t>>32);
+				const int has_wan = t&0x80000000;
+				const int wan_x = int(t&0x3fffffff);
+
+				int myleft = max(p-time, occ_x+1);
+				int myright = myleft + c - 1;
+				if(myright <= p+time) {
+					LL key = (LL(myright)<<32) | has_wan | wan_x;
+					int v = k;
+					cerr << "#" << myright << " " << (has_wan?1:0) << " " << wan_x << endl;
+					if(dp2.count(key)) dp2[key] = min(dp2[key], v); else dp2[key] = v;
+				}
+				if(has_wan && p-time <= wan_x) {
+					LL key = LL(occ_x)<<32 | 0x80000000 | wan_x;
+					int v = k;
+					cerr << "$" << occ_x << " " << 1 << " " << wan_x << endl;
+					if(dp2.count(key)) dp2[key] = min(dp2[key], v); else dp2[key] = v;
+				}
+				{
+					LL key = LL(occ_x)<<32 | 0x80000000 | (p+time);
+					int v = k + (has_wan?1:0);
+					cerr << "!" << occ_x << " " << 1 << " " << p+time << endl;
+					if(dp2.count(key)) dp2[key] = min(dp2[key], v); else dp2[key] = v;
+				}
+			}
+			dp = std::move(dp2);
+		}
+
+		int best = N;
+		for(auto& tk: dp) {
+			const LL t = tk.first;
+			const int k = tk.second;
+			const int occ_x = int(t>>32);
+			const int has_wan = t&0x80000000;
+			const int wan_x = int(t&0x3fffffff);
+			best = min(best, k + (has_wan?1:0));
+		}
+		return best;
+	}
+};
+
+// 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(_, CatsOnTheLineDiv1().getNumber(position, count, time));}
+int main(){
+
+CASE(0)
+	int position_[] = {0};
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = {7};
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = 3; 
+	int _ = 0; 
+END
+CASE(1)
+	int position_[] = {0};
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = {6};
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = 2; 
+	int _ = 1; 
+END
+CASE(2)
+	int position_[] = {4, 7, 47};
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = {4, 7, 4};
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = 1; 
+	int _ = 3; 
+END
+CASE(3)
+	int position_[] = {3, 0, 7, 10};
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = {3, 7, 4, 5};
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = 2; 
+	int _ = 2; 
+END
+CASE(4)
+	int position_[] = {-5, 0, 7};
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = {47, 85, 10};
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = 6; 
+	int _ = 1; 
+END
+CASE(5)
+	int position_[] = {-8, 12, -15, -20, 17, -5, 7, 10};
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = {20, 10, 7, 9, 2, 8, 11, 10};
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = 2; 
+	int _ = 5; 
+END
+	/*
+CASE(6)
+	int position_[] = ;
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = ;
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = ; 
+	int _ = ; 
+END
+CASE(7)
+	int position_[] = ;
+	  vector <int> position(position_, position_+sizeof(position_)/sizeof(*position_)); 
+	int count_[] = ;
+	  vector <int> count(count_, count_+sizeof(count_)/sizeof(*count_)); 
+	int time = ; 
+	int _ = ; 
+END
+	*/
+}
+// END CUT HERE