제출 #1072580

#제출 시각아이디문제언어결과실행 시간메모리
1072580redLotus31415Tracks in the Snow (BOI13_tracks)C++14
43.54 / 100
2116 ms817492 KiB
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <fstream> #include <string> #include <bits/stdc++.h> #include <numeric> using namespace std; #define FOR(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops" #define FOR_STEP(i,L,R, STEP) for (int i = L; i < R; i+= STEP) //next four are for "for loops" struct coord { int x; int y; }; int main(){ int H, W; cin >> H >> W; char array[H][W]; int connected[H][W]; bool visited[H][W]; FOR(i, 0, H) { FOR(j, 0, W) { char x; cin >> x; array[i][j] = x; connected[i][j] = -1; visited[i][j] = false; } } int left[] = {-1, 1, 0, 0}; int right[] = {0, 0, -1, 1}; int count = -1; stack<coord> DFSStack; map<int, set<int>> components; FOR(i, 0, H) { FOR(j, 0, W) { if (array[i][j] != '.') {count++; DFSStack.push({i,j});} while (!DFSStack.empty()) { coord topCoord = DFSStack.top(); DFSStack.pop(); connected[topCoord.x][topCoord.y]= count; FOR (k, 0, 4) { int nx = topCoord.x + left[k]; int ny = topCoord.y + right[k]; if (0 <= nx && nx < H && 0<= ny && ny < W) { if (array[nx][ny] != '.' && array[nx][ny] == array[topCoord.x][topCoord.y]) DFSStack.push({nx, ny}); else { if (connected[nx][ny] != -1) { components[count].insert(connected[nx][ny]); components[connected[nx][ny]].insert(count); } } } } array[topCoord.x][topCoord.y] = '.'; } } } queue<coord> BFSQ; // node and depth BFSQ.push({0, 0}); unordered_map<int, bool> BFSVisited; int maxDepth = 0; while (!BFSQ.empty()) { coord top = BFSQ.front(); BFSQ.pop(); BFSVisited[top.x] = true; maxDepth = max(maxDepth, top.y); for (auto const&neighbor: components[top.x]) { if (!BFSVisited[neighbor]) { BFSQ.push({neighbor, top.y+1}); } } } cout << maxDepth+1; }

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:25:10: warning: variable 'visited' set but not used [-Wunused-but-set-variable]
   25 |     bool visited[H][W];
      |          ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...