Submission #467763

#TimeUsernameProblemLanguageResultExecution timeMemory
467763YuisuyunoTracks in the Snow (BOI13_tracks)C++14
32.19 / 100
38 ms3120 KiB
//Nguyen Huu Hoang Minh #include <bits/stdc++.h> #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define reset(x) memset(x, 0,sizeof(x)) #define pb push_back #define mp make_pair #define fi first #define se second #define N 505 #define remain(x) if (x > MOD) x -= MOD #define ii pair<int, int> #define iiii pair< ii , ii > #define viiii vector< iiii > #define vi vector<int> #define vii vector< ii > #define bit(x, i) (((x) >> (i)) & 1) #define Task "test" #define int long long using namespace std; typedef long double ld; const int inf = 1e10; const int minf = -1e10; char a[N][N]; int n, m; void readfile() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); if (fopen(Task".inp","r")) { freopen(Task".inp","r",stdin); //freopen(Task".out","w",stdout); } cin >> n >> m; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ cin >> a[i][j]; } } } int d[N][N]; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; bool ok(int x, int y){ if (x < 1 || x > n || y < 1 || y > m) return false; return true; } void proc() { deque<ii> q; d[1][1] = 1; int ans = 1; q.push_front(ii(1,1)); while (q.size()){ int u = q.front().fi; int v = q.front().se; q.pop_front(); for(int i=0; i<4; i++){ int nu = u + dx[i]; int nv = v + dy[i]; if (ok(nu,nv) && a[nu][nv]!='.' && d[nu][nv]==0){ if (a[nu][nv]!=a[u][v]){ d[nu][nv] = d[u][v]+1; q.pb(ii(nu,nv)); ans = max(ans,d[nu][nv]); } else{ q.push_front(ii(nu,nv)); d[nu][nv] = d[u][v]; ans = max(ans,d[nu][nv]); } } } } cout << ans; } signed main() { readfile(); proc(); return 0; }

Compilation message (stderr)

tracks.cpp: In function 'void readfile()':
tracks.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(Task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...