회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
15683번 - 감시 반례 다 맞는것 같은데 1%도 안되서 틀리다고 나오네요
15683번 - 감시
gladicall
3년 전
0
테케 다 맞고, 게시판에 반례들 돌려봐도 맞는데
왜 1프로도 안되서 틀리다고 할까요..?
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <list> using namespace std; const int MAX = 20 + 1; //const int MAX = 6; int map[MAX][MAX]; int map1[MAX][MAX]; int map2[MAX][MAX][8]; //승객,도착정보만 표기 int map3[MAX][MAX]; bool bFound; bool bNever; int visit[MAX][MAX]; int cam_num; int res; int N; int M; int fuel; int first_sx; int first_sy; int off_y[4] = { 0,-1,0,1 }; int off_x[4] = { -1,0,1,0 }; int divd[2] = { 5,3 }; bool complete; struct MyStruct { int y; int x; int c; //손님이 아직 목적지에 안갔으면 1, 데려다줬으면 0 }; vector<MyStruct> start_vec; vector<MyStruct> obstacle_vec; vector<MyStruct> dest_vec; void reset_map2() { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { map3[i][j] = 0; } } } int count() { int zero = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (map3[i][j] == 0) { zero++; } } } return zero; } void fill_1way(int dir, int sy, int sx , int step) { int nx, ny; map2[sy][sx][step] = 9; if (dir > 4) { dir = dir - ((dir / 4) * 4); } if (dir == 1) //우측 { nx = sx + 1; while (1) { if (nx >= M || map[sy][nx] == 6) break; map2[sy][nx][step] = 9; nx++; } } if (dir == 3) //좌측 { nx = sx - 1; while (1) { if (nx < 0 || nx >= M || map[sy][nx] == 6) break; map2[sy][nx][step] = 9; nx--; } } if (dir == 2) //아래 { ny = sy + 1; while (1) { if (ny >= N || map[sx][ny] == 6) break; map2[ny][sx][step] = 9; ny++; } } if (dir == 4) //위 { ny = sy - 1; while (1) { if (ny < 0 || ny >= N || map[sx][ny] == 6) break; map2[ny][sx][step] = 9; ny--; } } } void del_1way(int dir, int sy, int sx, int step) { int nx, ny; map2[sy][sx][step] = 0; if (dir > 4) { dir = dir - ((dir / 4) * 4); } if (dir == 1) //우측 { nx = sx + 1; while (1) { if (nx >= M || map[sy][nx] == 6) break; map2[sy][nx][step] = 0; nx++; } } if (dir == 3) //좌측 { nx = sx - 1; while (1) { if (nx < 0 || nx >= M || map[sy][nx] == 6) break; map2[sy][nx][step] = 0; nx--; } } if (dir == 2) //아래 { ny = sy + 1; while (1) { if (ny >= N || map[sx][ny] == 6) break; map2[ny][sx][step] = 0; ny++; } } if (dir == 4) //위 { ny = sy - 1; while (1) { if (ny < 0 || ny >= N || map[sx][ny] == 6) break; map2[ny][sx][step] = 0; ny--; } } } void copy_obs_to_map2() { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { map3[i][j] = 0; } } int num_obs = obstacle_vec.size(); for (int i = 0; i < num_obs; i++) { int x, y; x = obstacle_vec[i].x; y = obstacle_vec[i].y; map3[y][x] = 6; } int num_cam = start_vec.size(); for (int k = 0; k < num_cam; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { map3[i][j] |= map2[i][j][k]; } } } } void dfs(int depth, int way) { if (depth == start_vec.size()) { //남은갯수 체크 //map2에 장애물 추가 copy_obs_to_map2(); int zero = count(); if (zero < res) res = zero; //reset_map2(); return; } int cx, cy; cy = start_vec[depth].y; cx = start_vec[depth].x; way = start_vec[depth].c; if (way == 1) { for (int i = 1; i <= 4; i++) { fill_1way(i, cy, cx, depth); dfs(depth + 1, 0); del_1way(i, cy, cx, depth); } } else if (way == 2) { for (int i = 1; i <= 2; i++) { fill_1way(i, cy, cx, depth); fill_1way(i + 2, cy, cx, depth); dfs(depth + 1, 0); del_1way(i, cy, cx, depth); del_1way(i + 2, cy, cx, depth); } } else if (way == 3) { for (int i = 1; i <= 4; i++) { fill_1way(i, cy, cx, depth); fill_1way(i + 1, cy, cx, depth); dfs(depth + 1, 0); del_1way(i, cy, cx, depth); del_1way(i + 1, cy, cx, depth); } } else if (way == 4) { for (int i = 1; i <= 4; i++) { fill_1way(i, cy, cx, depth); fill_1way(i + 1, cy, cx, depth); fill_1way(i + 2, cy, cx, depth); dfs(depth + 1, 0); del_1way(i, cy, cx, depth); del_1way(i + 1, cy, cx, depth); del_1way(i + 2, cy, cx, depth); } } else if (way == 5) { int i = 1; fill_1way(i, cy, cx, depth); fill_1way(i + 1, cy, cx, depth); fill_1way(i + 2, cy, cx, depth); fill_1way(i + 3, cy, cx, depth); dfs(depth + 1, 0); del_1way(i, cy, cx, depth); del_1way(i + 1, cy, cx, depth); del_1way(i + 2, cy, cx, depth); del_1way(i + 3, cy, cx, depth); } } int main() { int T; //freopen("input_alice.txt", "r", stdin); cin >> N; cin >> M; res = 2147483647; cam_num = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cin >> map[i][j]; if (map[i][j] != 6 && map[i][j] != 0) { start_vec.push_back({ i,j,map[i][j] }); } if (map[i][j] == 6) { obstacle_vec.push_back({ i,j,6 }); } } } dfs(0, 0); cout << res; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
gladicall 3년 전
테케 다 맞고, 게시판에 반례들 돌려봐도 맞는데
왜 1프로도 안되서 틀리다고 할까요..?