Artifact Content
Not logged in

Artifact 6cad379ca924cee74dd36bb491234fee65c52e6b


#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 ApplesAndOrangesEasy { public:
	int maximumApples(int N, int K, vector <int> info)
	{
		vector<bool> ate_apple(N, false);
		for(auto i: info)
			ate_apple[i-1] = true;
		for(int i=0; i<N; ++i)
			if(!ate_apple[i]) {
				ate_apple[i] = true;
				if(!ok(N,K,ate_apple))
					ate_apple[i] = false;
			}
		return count(ate_apple.begin(), ate_apple.end(), true);
	}

	bool ok(int N, int K, const vector<bool>& A)
	{
		int cnt = 0;
		for(int i=0; i<N; ++i) {
			if(A[i]) cnt++;
			if(i-K>=0 && A[i-K]) cnt--;
			if(cnt>K/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(_, ApplesAndOrangesEasy().maximumApples(N, K, info));}
int main(){

CASE(0)
	int N = 3; 
	int K = 2; 
	vector <int> info; 
	int _ = 2; 
END
CASE(1)
	int N = 10; 
	int K = 3; 
	int info_[] = {3, 8};
	  vector <int> info(info_, info_+sizeof(info_)/sizeof(*info_)); 
	int _ = 2; 
END
CASE(2)
	int N = 9; 
	int K = 4; 
	int info_[] = {1, 4};
	  vector <int> info(info_, info_+sizeof(info_)/sizeof(*info_)); 
	int _ = 5; 
END
CASE(3)
	int N = 9; 
	int K = 4; 
	int info_[] = {2, 4};
	  vector <int> info(info_, info_+sizeof(info_)/sizeof(*info_)); 
	int _ = 4; 
END
CASE(4)
	int N = 23; 
	int K = 7; 
	int info_[] = {3, 2, 9, 1, 15, 23, 20, 19};
	  vector <int> info(info_, info_+sizeof(info_)/sizeof(*info_)); 
	int _ = 10; 
END
/*
CASE(5)
	int N = ; 
	int K = ; 
	int info_[] = ;
	  vector <int> info(info_, info_+sizeof(info_)/sizeof(*info_)); 
	int _ = ; 
END
CASE(6)
	int N = ; 
	int K = ; 
	int info_[] = ;
	  vector <int> info(info_, info_+sizeof(info_)/sizeof(*info_)); 
	int _ = ; 
END
*/
}
// END CUT HERE