회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
예제는 다 통과하는데 0%에서 틀리네요(C++)
21610번 - 마법사 상어와 비바라기
kyungun07
2년 전
0
혹시 이 코드의 반례를 알 수 있을까요?
#include <iostream> #include <string> #include <vector> #include <queue> #include <algorithm> #include <map> #include <set> #include <deque> #include <unordered_set> void Init() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); } int worldSize; int world[52][52]; std::vector<std::pair<int, int>> moveActions; std::set<std::pair<int, int>> clouds; //←, ↖, ↑, ↗, →, ↘, ↓, ↙ const int dx[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }; const int dy[8] = { 0, -1, -1, -1, 0, 1, 1, 1 }; void Input(); void MoveClouds(int _dir, int _distance); void DropRain(); void CreateNewClouds(); int main() { Init(); Input(); for (const std::pair<int, int>& moveAction : moveActions) { int dir = moveAction.first; int distance = moveAction.second; MoveClouds(dir, distance); DropRain(); CreateNewClouds(); } int result = 0; for (int y = 0; y < worldSize; ++y) { for (int x = 0; x < worldSize; ++x) result += world[y][x]; } std::cout << result; return 0; } void Input() { int moveCount; std::cin >> worldSize >> moveCount; for (int y = 0; y < worldSize; ++y) { for (int x = 0; x < worldSize; ++x) std::cin >> world[y][x]; } moveActions.resize(moveCount); for (std::pair<int, int>& moveAction : moveActions) { std::cin >> moveAction.first; //dir std::cin >> moveAction.second; //distance --moveAction.first; moveAction.second %= worldSize; } //←, ↖, "↑, ↗, →", ↘, ↓, ↙ const std::vector<int> startClouds = { 2, 3, 4 }; const std::pair<int, int> pivotCloud = { worldSize - 1, 0 }; for (int index : startClouds) { std::pair<int, int> cloud; cloud.first = pivotCloud.first + dy[index]; cloud.second= pivotCloud.second+ dx[index]; clouds.insert(cloud); } clouds.insert(pivotCloud); } void MoveClouds(int _dir, int _distance) { std::set<std::pair<int, int>>::iterator startIter = clouds.begin(); std::set<std::pair<int, int>>::iterator endIter = clouds.end(); std::set<std::pair<int, int>> temp; while (startIter != endIter) { const int prevY = startIter->first; const int prevX = startIter->second; startIter = clouds.erase(startIter); int nextY = prevY + (dy[_dir] * _distance); int nextX = prevX + (dx[_dir] * _distance); nextY = (nextY < 0) ? (worldSize + nextY) : (nextY % worldSize); nextX = (nextX < 0) ? (worldSize + nextX) : (nextX % worldSize); temp.insert({ nextY, nextX }); } std::swap(temp, clouds); } void DropRain() { for (std::pair<int, int> cloud : clouds) { int y = cloud.first; int x = cloud.second; ++world[y][x]; } //←, ↖, ↑, ↗, →, ↘, ↓, ↙ static const std::vector<int> nearIndexes = { 1, 3, 5, 7 }; for (std::pair<int, int> cloud : clouds) { const int y = cloud.first; const int x = cloud.second; int acquireWater = 0; for (int nearIndex : nearIndexes) { const int nearY = y + dy[nearIndex]; const int nearX = x + dx[nearIndex]; if (y < 0 || x < 0 || worldSize <= y || worldSize <= x) continue; if (0 < world[nearY][nearX]) ++acquireWater; } world[y][x] += acquireWater; } } void CreateNewClouds() { std::set<std::pair<int, int>> temp; for (int y = 0; y < worldSize; ++y) { for (int x = 0; x < worldSize; ++x) { if (world[y][x] < 2) continue; std::pair<int, int> now = { y, x }; if (clouds.end() != clouds.find(now)) continue; world[y][x] -= 2; temp.insert(now); } } std::swap(temp, clouds); }
댓글을 작성하려면
로그인
해야 합니다.
kyungun07 2년 전
혹시 이 코드의 반례를 알 수 있을까요?