SRM517 Div2 Easy(250) MonochromaticBoard

MonochromaticBoard

Bだけの行と列を塗る。ただし、Wが1個も無ければ、幅と高さの小さい方が答え。

#include <string>
#include <vector>
using namespace std;

class MonochromaticBoard{public:
int theMin( vector <string> board )
{
    int h = (int)board.size();
    int w = (int)board[0].size();

    int ans = 0;

    for ( int y=0; y<h; y++ )
    {
        bool f = true;
        for ( int x=0; x<w; x++ )
            if ( board[y][x]!='B' )
                f = false;
        if ( f )
            ans++;
    }

    for ( int x=0; x<w; x++ )
    {
        bool f = true;
        for ( int y=0; y<h; y++ )
            if ( board[y][x]!='B' )
                f = false;
        if ( f )
            ans++;
    }

    return ans<w+h ? ans : min(w,h);
}};