회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
예제는 다 통과하는데 왜 제출하면 틀리는지 모르겠습니다
21610번 - 마법사 상어와 비바라기
yesming
1년 전
0
예제만 통과하고 제출하면 바로 틀리네요. 반례나 틀린 부분을 알려주세요 ㅠ
#include <stdio.h> #include <algorithm> #include <iostream> #include <numeric> #include <vector> using namespace std; vector<vector<int>> grid; vector<pair<int, int>> clouds; vector<vector<bool>> ready_rain; int N, M; vector<int> d; vector<int> s; const vector<int> dx = {0, 0, -1, -1, -1, 0, 1, 1, 1}; const vector<int> dy = {0, -1, -1, 0, 1, 1, 1, 0, -1}; const vector<int> diag_x = {-1, -1, 1, 1}; const vector<int> diag_y = {-1, 1, -1, 1}; void over_grid(int& x, int& y) { if (x < 0) { x = N - 1; } if (x >= N) { x = 0; } if (y < 0) { y = N - 1; } if (y >= N) { y = 0; } } bool is_out_of_grid(int& x, int& y) { if (x < 0 || y < 0 || x >= N || y >= N) { return true; } return false; } void move_clouds(int dir, int dist) { vector<vector<bool>> temp; temp.resize(N, vector<bool>(N, false)); ready_rain.resize(0, vector<bool>(0, false)); for (int j = 0; clouds.size() > j; ++j) { int x = clouds[j].first; int y = clouds[j].second; for (int k = 0; dist > k; ++k) { x += dx[dir]; y += dy[dir]; if (x < 0) x = N - 1; else if (x >= N) x = 0; if (y < 0) y = N - 1; else if (y >= N) y = 0; // over_grid(x, y); } clouds[j].first = x; clouds[j].second = y; temp[x][y] = true; } ready_rain = temp; } void do_raining() { for (int i = 0; clouds.size() > i; ++i) { grid[clouds[i].first][clouds[i].second]++; } } void copy_water() { for (int i = 0; clouds.size() > i; ++i) { int count = 0; int x = clouds[i].first; int y = clouds[i].second; for (int k = 0; 4 > k; ++k) { int temp_x = x + diag_x[k]; int temp_y = y + diag_y[k]; if (temp_x < 0 || temp_x < 0 || temp_x >= N || temp_x >= N) continue; if (grid[temp_x][temp_y] >= 1) { count++; } } grid[x][y] += count; } } void generate_clouds() { vector<pair<int, int>> temp = clouds; vector<vector<bool>> temp_cloud; temp_cloud.resize(N, vector<bool>(N, false)); clouds.clear(); for (int i = 0; N > i; ++i) { for (int j = 0; N > j; ++j) { if (grid[i][j] >= 2 && ready_rain[i][j] == false) { grid[i][j] -= 2; clouds.emplace_back(make_pair(i, j)); temp_cloud[i][j] = true; } } } ready_rain = temp_cloud; } void process() { for (int i = 0; M > i; ++i) { move_clouds(d[i], s[i]); do_raining(); copy_water(); generate_clouds(); } } int total_water() { int answer = 0; for (int i = 0; N > i; ++i) { for (int j = 0; N > j; ++j) { answer += grid[i][j]; } } return answer; } int main() { cin >> N >> M; // initialize clouds.emplace_back(make_pair(N - 1, 0)); clouds.emplace_back(make_pair(N - 1, 1)); clouds.emplace_back(make_pair(N - 2, 0)); clouds.emplace_back(make_pair(N - 2, 1)); ready_rain.resize(N, vector<bool>(N, false)); ready_rain[N - 1][0] = true; ready_rain[N - 1][1] = true; ready_rain[N - 2][0] = true; ready_rain[N - 2][1] = true; grid.resize(N, vector<int>(N, 0)); // input grid for (int i = 0; N > i; ++i) { for (int j = 0; N > j; ++j) { cin >> grid[i][j]; } } // input d.resize(M); s.resize(M); for (int i = 0; M > i; ++i) { cin >> d[i] >> s[i]; } process(); int answer = total_water(); cout << answer << "\n"; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
yesming 1년 전
예제만 통과하고 제출하면 바로 틀리네요. 반례나 틀린 부분을 알려주세요 ㅠ