|
| 1 | +#include <iostream> |
| 2 | +#include <sstream> |
| 3 | +#include <vector> |
| 4 | +#include <algorithm> |
| 5 | +#include <set> |
| 6 | +#include <map> |
| 7 | +#include <queue> |
| 8 | +#include <cstring> |
| 9 | +#include <climits> |
| 10 | +#include <cstdio> |
| 11 | +using namespace std; |
| 12 | +typedef pair<int,int> pi; |
| 13 | +typedef set<int> si; |
| 14 | +typedef vector<int> vi; |
| 15 | +typedef vector<vi> vvi; |
| 16 | +typedef vector<string> vs; |
| 17 | +#define mp make_pair |
| 18 | + |
| 19 | +class MLBRecord{ |
| 20 | + public: |
| 21 | + int rank(vi v, int i){ |
| 22 | + int count = 0; |
| 23 | + int val = v[i]; |
| 24 | + for(int j = 0; j < v.size(); j++) |
| 25 | + if(v[j] > val) count++; |
| 26 | + return count; |
| 27 | + } |
| 28 | + string teamStatus(vector <int> wins, int gamesLeft, int N) { |
| 29 | + int n = wins.size(); |
| 30 | + int total = (n*gamesLeft)/2; |
| 31 | + string ans(n, '.'); |
| 32 | + for(int i = 0; i < n; i++){ |
| 33 | + //Best Case |
| 34 | + int totaRank = 0; |
| 35 | + queue<pair<vi, int> > Q; |
| 36 | + vi team = wins; |
| 37 | + team[i] += gamesLeft; |
| 38 | + Q.push(mp(team, total-gamesLeft)); |
| 39 | + |
| 40 | + while(!Q.empty()){ |
| 41 | + |
| 42 | + auto p = Q.front(); |
| 43 | + Q.pop(); |
| 44 | + vi team = p.first, minv = team; |
| 45 | + int totalWin = p.second, minRank = 1000, minj = 0; |
| 46 | + if(totalWin == 0){ |
| 47 | + totaRank = rank(team, i); |
| 48 | + break; |
| 49 | + } |
| 50 | + |
| 51 | + for(int j = 0; j < n; j++){ |
| 52 | + if(i == j) continue; |
| 53 | + vi next = team; |
| 54 | + next[j]++; |
| 55 | + if(next[j]-wins[j] > gamesLeft) continue; |
| 56 | + int r = rank(next, i); |
| 57 | + if(r < minRank){ |
| 58 | + minRank = r; |
| 59 | + minv = next; |
| 60 | + minj = j; |
| 61 | + } |
| 62 | + else if(r == minRank && (next[minj]-wins[minj] > next[j]-wins[j])){ |
| 63 | + minv = next; |
| 64 | + minj = j; |
| 65 | + } |
| 66 | + } |
| 67 | + Q.push(mp(minv, totalWin-1)); |
| 68 | + } |
| 69 | + if(totaRank >= N){ |
| 70 | + ans[i] = 'E'; |
| 71 | + continue; |
| 72 | + } |
| 73 | + int done = 0; |
| 74 | + //Worst Case |
| 75 | + { |
| 76 | + |
| 77 | + int totaRank = 0; |
| 78 | + vi rest; |
| 79 | + |
| 80 | + for(int j = 0; j < n; j++){ |
| 81 | + if(i == j || wins[j] > wins[i]) continue; |
| 82 | + rest.push_back(wins[j]); |
| 83 | + } |
| 84 | + int rank = n-(rest.size()); |
| 85 | + sort(rest.rbegin(), rest.rend()); |
| 86 | + int totalWin = total, score = wins[i]; |
| 87 | + for(int t : rest){ |
| 88 | + int x = min(totalWin, min(score-t, gamesLeft)); |
| 89 | + t += x; |
| 90 | + if(t >= score) rank++; |
| 91 | + totalWin -= x; |
| 92 | + } |
| 93 | + if(rank <= N){ |
| 94 | + ans[i] = 'C'; |
| 95 | + done = 1; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + if(!done) ans[i] = '.'; |
| 100 | + |
| 101 | + } |
| 102 | + return ans; |
| 103 | + } |
| 104 | + |
| 105 | +// BEGIN CUT HERE |
| 106 | + public: |
| 107 | + void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); } |
| 108 | + private: |
| 109 | + template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } |
| 110 | + void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } |
| 111 | + void test_case_0() { int Arr0[] = {10,5,7,2}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 4; int Arg2 = 2; string Arg3 = "C..E"; verify_case(0, Arg3, teamStatus(Arg0, Arg1, Arg2)); } |
| 112 | + void test_case_1() { int Arr0[] = {1,1,1,3,4,5}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; int Arg2 = 3; string Arg3 = ".....C"; verify_case(1, Arg3, teamStatus(Arg0, Arg1, Arg2)); } |
| 113 | + void test_case_2() { int Arr0[] = {26,12,93,31,74,35,59,99,21}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 40; int Arg2 = 4; string Arg3 = ".EC....C."; verify_case(2, Arg3, teamStatus(Arg0, Arg1, Arg2)); } |
| 114 | + void test_case_3() { int Arr0[] = {26,12,93,31,74,35,59,99,21}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 22; int Arg2 = 4; string Arg3 = "EECECECCE"; verify_case(3, Arg3, teamStatus(Arg0, Arg1, Arg2)); } |
| 115 | + void test_case_4() { int Arr0[] = {10, 10, 10}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 0; int Arg2 = 2; string Arg3 = "..."; verify_case(4, Arg3, teamStatus(Arg0, Arg1, Arg2)); } |
| 116 | + void test_case_5() { int Arr0[] = {27, 40, 33, 20, 40}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 20; int Arg2 = 2; string Arg3 = "....."; verify_case(5, Arg3, teamStatus(Arg0, Arg1, Arg2)); } |
| 117 | + |
| 118 | +// END CUT HERE |
| 119 | + |
| 120 | +}; |
| 121 | + |
| 122 | +// BEGIN CUT HERE |
| 123 | +int main(){ |
| 124 | + |
| 125 | + MLBRecord ___test; |
| 126 | + ___test.run_test(-1); |
| 127 | +} |
| 128 | +// END CUT HERE |
0 commit comments