Submission #1307368

#TimeUsernameProblemLanguageResultExecution timeMemory
1307368tarner_exeTracks in the Snow (BOI13_tracks)C++20
100 / 100
1166 ms181660 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define elif else if
#define ft first
#define sc second
#define pb push_back
#define pII pair<int,int>
#define fast_IO ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)

const int sizen = 2e6+11;
const int sizen_s = 5e3+32;
const int oo = 1e16+11;

int visited[sizen_s][sizen_s];

int N,K;
int t=1, X;
int H,W;
int ODP = 0;
vector<int>vec[sizen];
char KAR[sizen_s][sizen_s];

void bfs()
{
    queue<pII>Q[2];
    int kolor = 0;
    
    Q[0].push({1,1});
    ODP ++;
    while(!Q[kolor].empty())
    {
        int x = Q[kolor].front().ft;
        int y = Q[kolor].front().sc;
        char moj;

        if(kolor == 0)
        {
            moj = KAR[1][1];
        }
        elif(1)
        {
            if(KAR[1][1] == 'F')
            {
                moj = 'R';
            }
            elif(1)
            {
                moj = 'F';
            }
        }
        if(x > 1 && visited[x-1][y] == 0 && KAR[x-1][y] != '.')
        {
            visited[x-1][y] = 1;
            if(KAR[x-1][y] == moj)
            {    
                Q[kolor].push({x-1,y});
            }            
            elif(1)
            {
                Q[(kolor^1)].push({x-1,y});
            }
        }
        if(x < W && visited[x+1][y] == 0 && KAR[x+1][y] != '.')
        {
            visited[x+1][y] = 1;
            if(KAR[x+1][y] == moj)
            {    
                Q[kolor].push({x+1,y});
            }            
            elif(1)
            {
                Q[(kolor^1)].push({x+1,y});
            }
        }
        if(y > 1 && visited[x][y-1] == 0 && KAR[x][y-1] != '.')
        {
            visited[x][y-1] = 1;
            if(KAR[x][y-1] == moj)
            {    
                Q[kolor].push({x,y-1});
            }            
            elif(1)
            {
                Q[(kolor^1)].push({x,y-1});
            }
        }
        if(y < H && visited[x][y+1] == 0 && KAR[x][y+1] != '.')
        {
            visited[x][y+1] = 1;
            if(KAR[x][y+1] == moj)
            {    
                Q[kolor].push({x,y+1});
            }            
            elif(1)
            {
                Q[(kolor^1)].push({x,y+1});
            }
        }

        Q[kolor].pop();
        if(Q[kolor].empty())
        {
            kolor^=1;
            if(!Q[kolor].empty())
            {
                ODP++;
            }
        }
    }

}

void solve()
{
    cin >> H >> W;
    for (int i = 1 ; i <= H;  i++)
    {
        for (int j = 1 ;  j <= W ; j++)
        {
            cin >> KAR[j][i];
        }
    }
    bfs();
    cout << ODP << "\n";
}
signed main()
{
    //cin >> t;
    while(t--)
    {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...