端から押し当てればいい。
本番で提出したコード
class GogoXCake { public: string solve(vector <string> cake, vector <string> cutter) { int ucell = 0; for (int i = 0; i < cutter.size(); ++i) { ucell += count(cutter[i].begin(), cutter[i].end(), '.'); } for (int i = 0; i < cake.size(); ++i) { for (int j = 0; j < cake[i].size(); ++j) { int c = 0; for (int k = 0; k < cutter.size() && i + k < cake.size(); ++k) { for (int l = 0; l < cutter[k].size() && j + l < cake[i + k].size(); ++l) { if (cutter[k][l] == '.' && cake[i + k][j + l] == '.') { ++c; } } } if (c == ucell) { for (int k = 0; k < cutter.size(); ++k) { for (int l = 0; l < cutter[k].size(); ++l) { if (cutter[k][l] == '.' && cake[i + k][j + l] == '.') { cake[i + k][j + l] = 'X'; } } } } } } for (int i = 0; i < cake.size(); ++i) { for (int j = 0; j < cake[i].size(); ++j) { if (cake[i][j] == '.') return "NO"; } } return "YES"; } };
0 件のコメント :
コメントを投稿