Submission #1287883

#TimeUsernameProblemLanguageResultExecution timeMemory
1287883quan606303Tracks in the Snow (BOI13_tracks)C++20
84.69 / 100
675 ms1114112 KiB
/*
 * @Author: RMQuan 
 * @Date: 2025-11-05 15:21:17 
 * @Last Modified by: RMQuan
 * @Last Modified time: 2025-11-05 15:23:47
 */
/*idea : 



*/
#include <bits/stdc++.h>
bool M1;
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define TASK "TEST"
#define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
using namespace std;
const int MOD=1e9+7;
const int maxn=4005;
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
int a[maxn][maxn],n,m;
bool vst[maxn][maxn];
int cnt=0;
bool check(int x,int y)
{
    return x>=1&&y>=1&&x<=n&&y<=m;
}
void dfs(int x,int y,int curr,vector<pair<int,int> >&n_vt,int &n_curr)
{
    vst[x][y]=true;
    for (int k=0;k<4;k++)
    {
        int u=x+dx[k];
        int v=y+dy[k];
        if (check(u,v)&&!vst[u][v])
        {
            if (a[u][v]==curr)dfs(u,v,curr,n_vt,n_curr);
            else if (a[u][v]==n_curr)n_vt.push_back({u,v});
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    file();
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            char x;
            cin>>x;
            if (x=='F')a[i][j]=1;
            else if (x=='R')a[i][j]=2;
            else a[i][j]=0;
        }
    }
    int ans=0;
    vector<pair<int,int> > vt;
    vt.push_back({1,1});
    int curr=a[1][1];
    while (vt.size())
    {
        vector<pair<int,int> > n_vt;
        int n_curr=(curr==1?2:1);
        for (auto i:vt)
        {
            if (!vst[i.fi][i.se])
            {
                dfs(i.fi,i.se,curr,n_vt,n_curr);
            }
        }
        ans++;
        swap(n_curr,curr);
        swap(n_vt,vt);
        n_vt.clear();
    }
    cout<<ans;
    bool M2;
    cerr<<"-------------------------------------------------"<<endl;
    cerr<<"Time : "<<clock()<<" ms"<<endl;
    cerr<<"Memory : "<<abs(&M2-&M1)/1024/1024<<" MB"<<endl;
    cerr<<"-------------------------------------------------"<<endl;
    return 0;
}

Compilation message (stderr)

tracks.cpp: In function 'int32_t main()':
tracks.cpp:24:50: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:56:5: note: in expansion of macro 'file'
   56 |     file();
      |     ^~~~
tracks.cpp:24:81: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:56:5: note: in expansion of macro 'file'
   56 |     file();
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...