회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례가 있을까요
2352번 - 반도체 설계
04_miffy
4년 전
0
반례가 있을까요..
시간초과면 이해가가는데 ㅠㅠㅠ 왜틀렸는지 모르겟어요 ㅠㅠㅠ
import sys class Semiconductor: def __init__(self, n, line): self.n = n self.inform = [] self.connected = [] for i in range(n): self.inform.append([i+1, line[i], abs(i+1-line[i])]) def make(self): self.inform = sorted(self.inform, key=lambda a: a[2]) self.connected.append(self.inform[0]) for item in self.inform[1:]: # print("{} 의 차례입니다".format(item)) if not self.isCross(item): # print("{}은 가능합니다".format(item)) self.connected.append(item) # print("") return len(self.connected) def isCross(self, item): length = len(self.connected) # print("connected: {}".format(self.connected)) # print("{}이 connected에 있는 것들에게 cross되는지 검사합니다".format(item)) for i in range(length): c = self.connected[i] # print("connected: {}, 검사할 item: {}".format(c, item)) if item[0] > c[0] and item[1] < c[1]: # print("cross") return True elif item[0] < c[0] and item[1] > c[1]: # print("cross") return True elif i == length-1: # print("ok") return False n = int(sys.stdin.readline()) line = input().split(" ") for i in range(n): line[i] = int(line[i]) s = Semiconductor(n, line) print(s.make())
nahwasa
4년 전
0
그쵸 틀렸으니 반례가.. 있죠!
10 1 10 2 9 3 8 4 7 5 6 답 : 6 출력 : 5
댓글을 작성하려면
로그인
해야 합니다.
04_miffy 4년 전
반례가 있을까요..
시간초과면 이해가가는데 ㅠㅠㅠ 왜틀렸는지 모르겟어요 ㅠㅠㅠ