Cod sursa(job #2552814)

Utilizator mihnea.anghelMihnea Anghel mihnea.anghel Data 21 februarie 2020 11:19:46
Problema Barbar Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <fstream>
#include <deque>
#define lin first
#define col second.first
#define val second.second
#define INF 1000100

using namespace std;
ifstream f("barbar.in");
ofstream g("barbar.out");
deque < pair < int, pair < int, int > > > d;
int n, i, j, m, xs, ys, xf, yf, ic, jc, iv, jv, dist, pas;
int a[1100][1100], distmin[1100][1100];
char ch;
int di[] = { -1, 1, 0, 0 };
int dj[] = { 0, 0, 1, -1 };

int main()
{
    f>>n>>m;
    for ( i=1; i <= n; i++ )
        for ( j=1; j <= m; j++ ){
            f>>ch;
            distmin[i][j] = INF;
            if ( ch == 'I' )
                xs = i, ys = j;
            if ( ch == 'D' ){
                d.push_back({i, {j, 0} });
                distmin[i][j] = 0;
            }
            if ( ch == 'O' )
                xf = i, yf = j;
            if ( ch == '*' )
                a[i][j] = -1, distmin[i][j] = -1;
        }
    while ( !d.empty() ){
        ic = d.front().lin;
        jc = d.front().col;
        dist = d.front().val;
        d.pop_front();
        for ( pas = 0; pas < 4; pas++ ){
            iv = ic+di[pas];
            jv = jc+dj[pas];
            if ( distmin[iv][jv] == INF ){
                distmin[iv][jv] = dist+1;
                d.push_back( { iv, { jv, dist+1 } } );
            }
        }
    }
    return 0;
}