ParallelProgramming srm 313 div2 hard
始められるやつから順番に始めて行く。ただそれだけ。サンプルデータでは合ってるんだけど、システムテストが通らない。。。何でだ。
#include <sstream> #include <string> #include <vector> #include <map> #include <algorithm> #include <iostream> #include <utility> #include <set> #include <cctype> #include <queue> #include <stack> #include <cstdio> #include <cstdlib> #include <cmath> #include <iterator> using namespace std; template<class T> ostream& operator<<(ostream& ost, const vector<T>& v){ copy(v.begin(), v.end(), ostream_iterator<T>(ost, "\t")); return ost; } class ParallelProgramming{ public: vector<int> start; vector<int> finish; vector<int> time; vector<string> prec; int n; int now; int minTime(vector <int> time_, vector <string> prec_){ setup(time_, prec_); print(); if(!launch()) return -1; while(!allFinish()){ print(); proceed(); launch(); } print(); return now; } void print(){ cout << now << "\t" << start << finish << endl; } void proceed(){ int buf = INT_MAX; for(int i = 0; i < n; i++){ if(finish[i] > now){ buf = min(buf, finish[i]); } } now = buf; } bool allFinish(){ for(int i = 0; i < n; i++){ if(now < finish[i]) return false; } return true; } bool launch(){ bool ret = false; for(int i = 0; i < n; i++){ if(start[i] < 0){ bool launchI = true; for(int j = 0; j < n; j++){ if(prec[j][i] == 'Y'){ launchI = (now >= finish[j]); } } if(launchI){ start[i] = now; finish[i] = now + time[i]; ret = true; } } } return ret; } void setup(vector<int> t, vector<string> p){ time = t; prec = p; n = time.size(); start.resize(n); fill(start.begin(), start.end(), -1); finish.resize(n); fill(finish.begin(), finish.end(), INT_MAX); now = 0; } };