제출 #413291

#제출 시각아이디문제언어결과실행 시간메모리
413291mat_v밀림 점프 (APIO21_jumps)C++14
0 / 100
341 ms40124 KiB
#include "jumps.h" #include <bits/stdc++.h> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) using namespace std; int n; int niz[200005]; int levo[200005][20]; int desno[200005][20]; int pravi[200005][20]; void init(int N, std::vector<int> H) { n = N; ff(i,0,n - 1)niz[i + 1] = H[i]; stack<int> s; ff(i,1,n){ while(!s.empty() && niz[s.top()] < niz[i])s.pop(); if(!s.empty())levo[i][0] = s.top(); s.push(i); } while(!s.empty())s.pop(); fb(i,n,1){ while(!s.empty() && niz[s.top()] < niz[i])s.pop(); if(!s.empty())desno[i][0] = s.top(); s.push(i); } fb(i,n,1){ ff(j,1,18)desno[i][j] = desno[desno[i][j - 1]][j - 1]; } ff(i,1,n){ ff(j,1,18)levo[i][j] = levo[levo[i][j - 1]][j - 1]; } fb(i,n - 1,1){ int lv = levo[i][0], rv = desno[i][0]; if(niz[lv] > niz[rv])pravi[i][0] = lv; else pravi[i][0] = rv; ff(j,1,18)pravi[i][j] = pravi[pravi[i][j - 1]][j - 1]; } } int minimum_jumps(int A, int B, int C, int D) { A++; B++; C++; D++; int l1,r1,l2,r2; l1 = A, r1 = B, l2 = C, r2 = D; int tr = l2; fb(j,18,0){ if(desno[tr][j] && desno[tr][j] <= r2)tr = desno[tr][j]; } int val = niz[tr]; int lv = r1; fb(j,18,0){ if(levo[lv][j] && levo[lv][j] >= l1 && niz[levo[lv][j]] < val)lv = levo[lv][j]; } if(niz[lv] > val)return -1; int poc = l2; fb(j,18,0){ if(desno[poc][j] && desno[poc][j] <= r2 && niz[desno[poc][j]] < niz[lv])poc = desno[poc][j]; } if(niz[poc] < niz[lv])poc = desno[poc][0]; lv = A; poc = C; int ans = 0; fb(j,18,0){ if(pravi[lv][j] && niz[pravi[lv][j]] < niz[poc]){ ans += (1<<j); lv = pravi[lv][j]; } } fb(j,18,0){ if(desno[lv][j] && niz[desno[lv][j]] < niz[poc]){ ans += (1<<j); lv = desno[lv][j]; } } if(desno[lv][0] == poc)return ans+1; return -1; return 0; }

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

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
jumps.cpp:16:5: note: in expansion of macro 'ff'
   16 |     ff(i,0,n - 1)niz[i + 1] = H[i];
      |     ^~
jumps.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
jumps.cpp:18:5: note: in expansion of macro 'ff'
   18 |     ff(i,1,n){
      |     ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:24:5: note: in expansion of macro 'fb'
   24 |     fb(i,n,1){
      |     ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:29:5: note: in expansion of macro 'fb'
   29 |     fb(i,n,1){
      |     ^~
jumps.cpp:3:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
jumps.cpp:30:9: note: in expansion of macro 'ff'
   30 |         ff(j,1,18)desno[i][j] = desno[desno[i][j - 1]][j - 1];
      |         ^~
jumps.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
jumps.cpp:32:5: note: in expansion of macro 'ff'
   32 |     ff(i,1,n){
      |     ^~
jumps.cpp:3:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
jumps.cpp:33:9: note: in expansion of macro 'ff'
   33 |         ff(j,1,18)levo[i][j] = levo[levo[i][j - 1]][j - 1];
      |         ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:35:5: note: in expansion of macro 'fb'
   35 |     fb(i,n - 1,1){
      |     ^~
jumps.cpp:3:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
jumps.cpp:39:9: note: in expansion of macro 'ff'
   39 |         ff(j,1,18)pravi[i][j] = pravi[pravi[i][j - 1]][j - 1];
      |         ^~
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:52:5: note: in expansion of macro 'fb'
   52 |     fb(j,18,0){
      |     ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:58:5: note: in expansion of macro 'fb'
   58 |     fb(j,18,0){
      |     ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:64:5: note: in expansion of macro 'fb'
   64 |     fb(j,18,0){
      |     ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:73:5: note: in expansion of macro 'fb'
   73 |     fb(j,18,0){
      |     ^~
jumps.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
      |                           ^
jumps.cpp:79:5: note: in expansion of macro 'fb'
   79 |     fb(j,18,0){
      |     ^~
#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...