Submission #569869

#TimeUsernameProblemLanguageResultExecution timeMemory
569869Uniq0rnTracks in the Snow (BOI13_tracks)C++14
2.19 / 100
1172 ms94576 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int,int> #define pb push_back #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() const int N = 4e3+10; char a[N][N]; int visited[N][N]; queue<pi> q; int main() { cin.tie(0)->sync_with_stdio(0); int r,c;cin >> r >> c; for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ cin >> a[i][j]; } } visited[1][1] = 1; q.push({1,1}); set<char> ans; while(sz(q)){ int ni = q.front().first,nj = q.front().second; ans.insert(a[ni][nj]); q.pop(); for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++){ if(abs(i) == abs(j)) continue; int ii = ni+i,jj = nj+j; if(ii < 1 || ii > r || jj < 1 || jj > c) continue; if(visited[ii][jj]) continue; visited[ii][jj] = 1; q.push({ii,jj}); } } cout << sz(ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...