Submission #1165981

#TimeUsernameProblemLanguageResultExecution timeMemory
1165981sasdeTracks in the Snow (BOI13_tracks)C++20
100 / 100
535 ms127072 KiB
#include<bits/stdc++.h>
#define task "strdel"
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define emf emplace_front
#define em emplace
using namespace std;
const int N=4e3+5,lg=20,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
char a[N][N];
int n,m;
bool check(int u,int v){
    return u>=1&&u<=n&&v>=1&&v<=m;
}
int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};
int dp[N][N];
void solve(){
    cin >> n >> m;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j)cin >> a[i][j];
    }
    deque<ii>p;
    int ans=1;
    memset(dp,-1,sizeof dp);
    dp[1][1]=1;
    p.emf(1,1);
    while(!p.empty()){
        int u=p.front().fi;
        int v=p.front().se;
        p.pop_front();
        for(int i=0;i<4;++i){
            int x=dx[i]+u;
            int y=v+dy[i];
            if(check(x,y)&&a[x][y]!='.'&&dp[x][y]==-1){
                dp[x][y]=dp[u][v]+(a[x][y]!=a[u][v]);
                if(a[x][y]!=a[u][v])
                p.emb(x,y);
            else p.emf(x,y);
                ans=max(ans,dp[x][y]);
            }
        }
    }
    cout << ans;
}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();
    cout<<'\n';
}

}

Compilation message (stderr)

tracks.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
tracks.cpp: In function 'int main()':
tracks.cpp:67:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:68:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...