SRM458 Div2 Easy(250) Desertification

Desertification

#include <string>
#include <vector>

using namespace std;

class Desertification
{
public:
    int desertArea( vector <string> island, int T );
};

int Desertification::desertArea( vector <string> island, int T )
{
    int h = (int)island.size();
    int w = (int)island[0].length();

    for ( int t=0; t<min(T,h+w); t++ )
    {
        vector<string> temp = island;

        for ( int y=0; y<h; y++ )
        for ( int x=0; x<w; x++ )
        if ( temp[y][x] == 'D' )
        {
            for ( int d=0; d<4; d++ )
            {
                if ( x >= 1 )   island[y][x-1] = 'D';
                if ( y >= 1 )   island[y-1][x] = 'D';
                if ( x < w-1 )  island[y][x+1] = 'D';
                if ( y < h-1 )  island[y+1][x] = 'D';
            }
        }
    }

    int c = 0;
    for ( int y=0; y<h; y++ )
    for ( int x=0; x<w; x++ )
        if ( island[y][x] == 'D' )
            c++;
    return c;
}