何日目まで店に通うかを決め打ちする。
int f(char c) { if ('0' <= c && c <= '9') return c - '0'; if ('A' <= c && c <= 'Z') return c - 'A' + 10; if ('a' <= c && c <= 'z') return c - 'a' + 36; return 0; } class MysteriousRestaurant { public: int maxDays(vector <string> P, int B) { const int F = P[0].size(); for (int i = 0; i < (int)P.size(); ++i) { int sum[7][F]; fill(&sum[0][0], &sum[7 - 1][F], 0); for (int j = 0; j < (int)F; ++j) { for (int k = 0; k <= (int)i; ++k) { sum[k % 7][j] += f(P[k][j]); } } int b = 0; for (int j = 0; j < (int)7; ++j) { int mn = 1 << 30; for (int k = 0; k < (int)F; ++k) { mn = min(mn, sum[j][k]); } b += mn; } if (b <= B) ; else return i; } return P.size(); } };