회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
1
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
어디부분이 문제인지모르겠습니다.
1725번 - 히스토그램
qktlf789456
3년 전
0
틀렸습니다. 이유를 모르겠네요 반례는 다 맞았는데도 그러네요 ㅠ
#include <iostream> #include <algorithm> #include <math.h> #define EMPTY -215214 using namespace std; /* ios_base::sync_with_stdio(0); cin.tie(0); 7 2 1 4 5 1 3 3 */ struct node { long long data; struct node* link; }; struct node* top = NULL; void push(long long data) { struct node* newnode = new struct node; newnode->data = data; newnode->link = top; top = newnode; } long long pop() { if (top == NULL) return 0; struct node* return_node = top; top = top->link; long long return_value = return_node->data; delete return_node; return return_value; } long long stack_empty() { return top == NULL; } long long get_top() { if (top == NULL) return -1; return top->data; } int n; long long* height; long long max_height = 0; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; height = new long long[n]; for (int i = 0; i < n; i++) { cin >> height[i]; } push(0); for (int i = 1; i <= n; i++) { if (i < n && height[get_top()] <= height[i]) //현재가 더 클 경우 { push(i); } else //현재가 더 작을경우 하나씩 빼가면서 비교 { while (stack_empty() == 0) { long long tmp_height = height[pop()]; long long width = i - get_top() -1; //cout << "[ " << tmp_height << " : " <<tmp_height * width <<"]" << i-1 << " ~ " << get_top()<< endl; max_height = max_height >= tmp_height * width ? max_height : tmp_height * width; } push(i); } } cout << max_height; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
qktlf789456 3년 전
틀렸습니다. 이유를 모르겠네요 반례는 다 맞았는데도 그러네요 ㅠ