Artifact Content
Not logged in

Artifact 0ca2f3e8b8b48b53d7b47b7a85d40eb3b070ca7e


#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