제출 #1129580

#제출 시각아이디문제언어결과실행 시간메모리
1129580patgraRoad Service 2 (JOI24_ho_t5)C++20
0 / 100
3097 ms59960 KiB
#include <bits/stdc++.h> #define rep(a,b,c) for(auto a = (b); a != (c); a++) #define repD(a,b,c) for(auto a = (b); a != (c); a--) #define repIn(a, b) for(auto& a : (b)) #define repIn2(a, b, c) for(auto& [a, b] : c) #define ll long long constexpr bool dbg = 0; #define DEBUG if constexpr(dbg) #define DC DEBUG std::cerr #define eol std::endl using namespace std; constexpr int maxn = 1e6 + 7, maxLog = 21; int h, w, q, n; vector<int> graf[maxn]; int component[maxn], top[maxn], bottom[maxn]; int jp[maxn][maxLog]; int rowCosts[maxn]; void input() { scanf("%d%d%d", &h, &w, &q); int x; char c; rep(i, 0, h) rep(j, 0, w - 1) scanf(" %c", &c), (c == '1' ? graf[i * w + j].push_back(i * w + j + 1), graf[i * w + j + 1].push_back(i * w + j), 0 : 0); rep(i, 0, h - 1) rep(j, 0, w) scanf(" %c", &c), (c == '1' ? graf[i * w + j].push_back(i * w + j + w), graf[i * w + j + w].push_back(i * w + j), 0 : 0); rep(i, 0, h) scanf("%d", rowCosts + i); } void dfsComponents(int v, int c) { component[v] = c; top[c] = min(top[c], v / w); bottom[c] = max(bottom[c], v / w); repIn(u, graf[v]) if (!component[u]) dfsComponents(u, c); } void calcComponents() { rep(i, 0, h) rep(j, 0, w) if (!component[i * w + j]) { n++; top[n] = bottom[n] = i; dfsComponents(i * w + j, n); DC << "Component " << n << " from " << i << ' ' << j << " -> top " << top[n] << " bottom " << bottom[n] << eol; } } int query(int v, int u) { if (bottom[v] > bottom[u]) swap(u, v); if (u == v) return 0; int ans = 0; // TODO: JP DC << "query " << v << ' ' << u << eol << ' '; while (top[u] > bottom[v]) { pair<int, int> lowest = {bottom[v], v}; rep(i, 1, n + 1) if (top[i] <= bottom[v]) lowest = max(lowest, {bottom[i], i}); ans++; if (lowest.second == v) return -1; v = lowest.second; DC << v << ' '; } DC << eol; return ans + 1; } void processQueries() { int t, a, b, c, d; rep(i, 0, q) { // TODO: more vertices scanf("%d%d%d%d%d", &t, &a, &b, &c, &d); a--; b--; c--; d--; printf("%d\n", query(component[a * w + b], component[c * w + d])); } } int main() { input(); calcComponents(); processQueries(); return 0; }

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

Main.cpp: In function 'void input()':
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d%d%d", &h, &w, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:40: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     rep(i, 0, h) rep(j, 0, w - 1) scanf(" %c", &c), (c == '1' ? graf[i * w + j].push_back(i * w + j + 1), graf[i * w + j + 1].push_back(i * w + j), 0 : 0);
      |                                   ~~~~~^~~~~~~~~~~
Main.cpp:29:40: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     rep(i, 0, h - 1) rep(j, 0, w) scanf(" %c", &c), (c == '1' ? graf[i * w + j].push_back(i * w + j + w), graf[i * w + j + w].push_back(i * w + j), 0 : 0);
      |                                   ~~~~~^~~~~~~~~~~
Main.cpp:30:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     rep(i, 0, h) scanf("%d", rowCosts + i);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void processQueries()':
Main.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d%d%d%d%d", &t, &a, &b, &c, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...