제출 #72020

#제출 시각아이디문제언어결과실행 시간메모리
72020 (#118)Box Run (FXCUP3_box)C++17
100 / 100
189 ms7640 KiB
#include <cstdio>
#include <climits>
#include <stack>
using namespace std;

struct S { int x, h; };

int p[500002];
int ans[500002];

stack<S> st;

int main(){
  int N; scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", &p[i]);

  for(int i = 1; i <= N; i++) ans[i] = -1;

  st.push({ 0, INT_MAX });

  int last = 0;

  for(int i = 1; i <= N; i++){
    while(!st.empty() && p[i] > st.top().h){
      st.pop();
    }

    int width = i - st.top().x - 1;

    if(width > last){
      for(int x = last + 1; x <= width; x++) ans[x] = i - x;
      last = width;
    }

    st.push({ i, p[i] });
  }

  for(int i = 1; i <= N; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}

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

box.cpp: In function 'int main()':
box.cpp:14:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int N; scanf("%d", &N);
          ~~~~~^~~~~~~~~~
box.cpp:15:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= N; i++) scanf("%d", &p[i]);
                               ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...