Submission #1120756

#TimeUsernameProblemLanguageResultExecution timeMemory
1120756HasanV11010238Tracks in the Snow (BOI13_tracks)C++17
75.94 / 100
2055 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long long #define INF 1000000000 vector<vector<vector<int>>> v; int bfs(int n, int st){ vector<int> di(n + 6, INF), us(n + 6, 0); deque<int> q; di[st] = 0; q.push_back(st); while (!q.empty()){ int x = q.front(); q.pop_front(); if (us[x]) continue; us[x] = 1; for (auto el : v[x]){ if (el[0] >= di.size()) return -1; if (di[el[0]] > di[x] + el[1]){ di[el[0]] = di[x] + el[1]; if (el[1] == 0){ q.push_front(el[0]); } else{ q.push_back(el[0]); } } } } int ans = 0; for (int i = 0; i < n; i++){ if (di[i] == INF) continue; ans = max(ans, di[i]); } return ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; v.resize((n + 5) * (m + 5)); vector<string> s(n); for (int i = 0; i < n; i++){ cin>>s[i]; for (int j = 0; j < m; j++){ if (s[i][j] == '.') continue; int v1 = (i + 1) * m + j + 1; if (i != 0 && s[i - 1][j] != '.'){ int v2 = i * m + j + 1; if (v.size() <= max(v1, v2)){ cout<<-1; return 0; } int va; if (s[i][j] == s[i - 1][j]){ va = 0; } else{ va = 1; } v[v1].push_back({v2, va}); v[v2].push_back({v1, va}); } if (j != 0 && s[i][j - 1] != '.'){ int v2 = (i + 1) * m + j; int va; if (v.size() <= max(v1, v2)){ cout<<-1; return 0; } if (s[i][j] == s[i][j - 1]){ va = 0; } else{ va = 1; } v[v1].push_back({v2, va}); v[v2].push_back({v1, va}); } } } cout<<bfs((n + 1) * (m + 1), m + 1) + 1; }

Compilation message (stderr)

tracks.cpp: In function 'int bfs(int, int)':
tracks.cpp:18:23: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |             if (el[0] >= di.size()) return -1;
tracks.cpp: In function 'int main()':
tracks.cpp:52:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   52 |                 if (v.size() <= max(v1, v2)){
      |                     ~~~~~~~~~^~~~~~~~~~~~~~
tracks.cpp:69:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   69 |                 if (v.size() <= max(v1, v2)){
      |                     ~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...