Submission #114941

#TimeUsernameProblemLanguageResultExecution timeMemory
114941jwvg0425산악 구조대 (JOI13_mountain)C++17
0 / 100
12 ms896 KiB
#include <algorithm> #include "grader.h" #define xx first #define yy second using namespace std; using ii = pair<int, int>; int GetH(int R, int C, int RS, int CS, int D) { int ans = 1000000001; if (D < 0) return ans; int ds[] = { RS + CS - 2, R - RS + CS - 1, R + C - RS - CS, RS - 1 + C - CS }; int md = *max_element(ds, ds + 4); if (md == ds[0]) if (RS > CS) return Measure(RS - (D + 1) / 2, CS - D / 2); else return Measure(RS - D / 2, CS - (D + 1) / 2); if (md == ds[1]) if (R - RS > CS - 1) return Measure(RS + (D + 1) / 2, CS - D / 2); else return Measure(RS + D / 2, CS - (D + 1) / 2); if (md == ds[2]) if (R - RS > C - CS) return Measure(RS + (D + 1) / 2, CS + D / 2); else return Measure(RS + D / 2, CS + (D + 1) / 2); if (RS - 1 > C - CS) return Measure(RS - (D + 1) / 2, CS + D / 2); else return Measure(RS - D / 2, CS + (D + 1) / 2); } bool Find(int R, int C, int RS, int CS, int D, int X) { if (D == 0) { int h = Measure(RS, CS); if (h == X) { Pinpoint(RS, CS); return true; } return false; } int sx = RS - D, sy = CS; int dx[] = { 0, 1, 1, -1, -1 }; int dy[] = { 0, 1, -1, -1, 1 }; int di = 0; for(int i = 0; i < 4 * D; i++, sx += dx[di], sy += dy[di]) { if (i % D == 0) di++; if (sx < 1 || sx > R || sy < 1 || sy > C) continue; int h = Measure(sx, sy); if (h == X) { Pinpoint(sx, sy); return true; } } return false; } void Rescue(int R, int C, int RS, int CS, int X) { // 모서리 4개, 가운데 4개로 max, min을 특정할 수 있다. // 속하는 영역을 이분 탐색으로 찾은 후 거기 밀기 int l = 1, r = max(R - RS, RS - 1) + max(C - CS, CS - 1); int ans = r; while (l <= r) { int mid = (l + r) / 2; int nowMin = GetH(R, C, RS, CS, mid); int upMin = GetH(R, C, RS, CS, mid - 1); if (nowMin <= X && X <= upMin) { ans = mid; break; } if (nowMin < X) r = mid - 1; else l = mid + 1; } // ans거리에서 탐색 if (!Find(R, C, RS, CS, ans, X)) Find(R, C, RS, CS, ans - 1, X); }

Compilation message (stderr)

mountain.cpp: In function 'int GetH(int, int, int, int, int)':
mountain.cpp:25:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
  if (md == ds[0])
     ^
mountain.cpp:31:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
  if (md == ds[1])
     ^
mountain.cpp:37:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
  if (md == ds[2])
     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...