제출 #491790

#제출 시각아이디문제언어결과실행 시간메모리
491790VictorTracks in the Snow (BOI13_tracks)C++17
71.56 / 100
2099 ms1048580 KiB
// #pragma GCC target ("avx,avx2,fma") // #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast // #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); ++i) #define per(i, a, b) for (int i = (b - 1); i >= (a); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) x.size() #define pb push_back #define debug(x) cout << #x << " = " << x << endl #define umap unordered_map #define uset unordered_set typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const int INF = 1'000'000'007; int dr[] = {1, -1, 0, 0}; int dc[] = {0, 0, -1, 1}; bitset<4001> visited[4001], taken[4001]; string grid[4001]; int rows, cols, num_marked = 0, ans = 0; char cur_animal; vii cur_vis; bool valid(int row, int col) { return 0 <= row && row < rows && 0 <= col && col < cols; } void dfs(int row, int col) { visited[row][col] = taken[row][col] = 1; rep(i, 0, 4) { int nr = row + dr[i], nc = col + dc[i]; if (valid(nr, nc)) { if (!visited[nr][nc] && grid[nr][nc] == cur_animal) dfs(nr, nc); if (!taken[nr][nc] && grid[nr][nc] != cur_animal && grid[nr][nc] != '.') { taken[nr][nc] = 1; cur_vis.emplace_back(nr, nc); } } } } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cin >> rows >> cols; rep(i, 0, rows) { cin >> grid[i]; trav(cell, grid[i]) if (cell != '.')++ num_marked; } cur_animal = grid[0][0]; cur_vis.emplace_back(0,0); int start = 0; while (!cur_vis.empty()) { int siz=sz(cur_vis); rep(i,start,siz) { int row, col; tie(row, col) = cur_vis[i]; if (!valid(row, col)) continue; if (!visited[row][col]) dfs(row, col); } if (cur_animal == 'F') cur_animal = 'R'; else cur_animal = 'F'; ++ans; if(siz==sz(cur_vis))break; } cout << ans << endl; return 0; }

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

tracks.cpp: In function 'int main()':
tracks.cpp:88:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         if(siz==sz(cur_vis))break;
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...