Submission #875936

#TimeUsernameProblemLanguageResultExecution timeMemory
875936431jerichoTracks in the Snow (BOI13_tracks)C++14
0 / 100
2087 ms2736 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF (int)1e18 #define endl '\n' const int mod = 1000 * 1000 * 1000 + 7; const int N = 4005; #define f first #define s second mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); char a[N][N]; queue<pair<int,int> > pq , nq; int vis[N][N]; int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; void Solve() { int n , m; cin>>n>>m; for(int i = 1 ;i<= n ; i++){ for(int j = 1; j<= m ; j++){ cin>>a[i][j]; } } int cnt = 0; char c ; vis[1][1] = true; pq.push({1,1}); while (!pq.empty()){ cnt++; c = a[pq.front().first][pq.front().second]; while (!pq.empty())nq.push(pq.front()) , pq.pop(); while (!nq.empty()){ auto v = nq.front(); nq.pop(); for (int i = 0; i < 4; ++i) { int nx = v.first+dx[i], ny = v.second + dy[i]; if (nx<1 || ny<1 ||nx>n ||ny>m || a[nx][ny]=='.' || vis[nx][ny]){ vis[nx][ny] = true; if (a[nx][ny]==c){ nq.push({nx,ny}); } else{ pq.push({nx,ny}); } } } } } cout<<cnt<<endl; } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(false); cin.tie(0); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }

Compilation message (stderr)

tracks.cpp: In function 'int32_t main()':
tracks.cpp:60:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...