회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
C# 런타임 에러 어디서 발생하는 걸까요?....
2529번 - 부등호
dbwls6056
3년 전
0
질문게시판 읽었는데도 도저히 모르겠어서 질문 남깁니다..
답변 부탁드립니다!!!ㅠㅠ
using System; using System.IO; using System.Text; namespace ConsoleApplication1 { class Program { static bool[] visit = new bool[10]; // 0 ~ 9 static int[] arr; static string[] oper; static int K; static StringBuilder sb = new StringBuilder(); static void Main(string[] args) { StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); StreamReader sr = new StreamReader(Console.OpenStandardInput()); sw.AutoFlush = true; K = Convert.ToInt32(sr.ReadLine()); arr = new int[K + 1]; oper = new string[K]; string[] input = sr.ReadLine().Split(' '); for (int i = 0; i < input.Length; i++) oper[i] = input[i]; int num, numIdx, operIdx; int ret = -1; numIdx = 0; operIdx = 0; // max num if (oper[0] == "<") num = 8; else num = 10; while (ret < 0) { int next = -1; while (next == -1) { if (oper[operIdx] == "<") { next = GetNextNum(num); } else if (oper[operIdx] == ">") { next = GetPrevNum(num); } } visit[next] = true; arr[numIdx] = next; ret = MAXDFS(numIdx + 1, operIdx, next); visit[next] = false; if (ret == -1) { num--; } } arr = new int[K + 1]; // min num if (oper[0] == "<") num = -1; else num = 2; ret = -1; numIdx = 0; operIdx = 0; while (ret < 0) { int next = -1; while (next == -1) { if (oper[operIdx] == "<") { next = GetNextNum(num); } else if (oper[operIdx] == ">") { next = GetPrevNum(num); } } visit[next] = true; arr[numIdx] = next; ret = MINDFS(numIdx + 1, operIdx, next); visit[next] = false; if (ret == -1) { num++; } } // print sw.WriteLine(sb.ToString()); } private static int MAXDFS(int numIdx, int operIdx, int num) { if (numIdx == (K + 1)) { for (int i = 0; i < arr.Length; i++) sb.Append(arr[i].ToString()); sb.Append("\n"); return 0; } int ret = -1; while (ret < 0) { int next = -1; while (next == -1) { if (oper[operIdx] == "<") { next = GetNextNum(num); } else if (oper[operIdx] == ">") { next = GetPrevNum(num); } if (next == -1) return -1; } visit[next] = true; arr[numIdx] = next; ret = MAXDFS(numIdx + 1, operIdx + 1, next); visit[next] = false; if (ret == -1) { num = next - 1; if (visit[num] == true) return -1; else num++; } } return 0; } private static int MINDFS(int numIdx, int operIdx, int num) { if(numIdx == (K + 1)) { for(int i = 0; i < arr.Length; i++) sb.Append(arr[i].ToString()); sb.Append("\n"); return 0; } int ret = -1; while (ret < 0) { int next = -1; while (next == -1) { if (oper[operIdx] == "<") { next = GetNextNum(num); } else if (oper[operIdx] == ">") { next = GetPrevNum(num); } if (next == -1) return -1; } visit[next] = true; arr[numIdx] = next; ret = MINDFS(numIdx + 1, operIdx + 1, next); visit[next] = false; if (ret == -1) { num = next + 1; if (visit[num] == true) return -1; else num--; } } return 0; } private static int GetPrevNum(int num) { for(int i = num - 1; i >= 0; i--) { if (visit[i] == false) return i; } return -1; } private static int GetNextNum(int num) { for (int i = num + 1; i < visit.Length; i++) { if (visit[i] == false) return i; } return -1; } } }
댓글을 작성하려면
로그인
해야 합니다.
dbwls6056 3년 전
질문게시판 읽었는데도 도저히 모르겠어서 질문 남깁니다..
답변 부탁드립니다!!!ㅠㅠ