회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례가 궁금합니다.
17822번 - 원판 돌리기
vire3064
4년 전
0
빠짐없이 구현한 것 같은데 테케는 다맞고 제출하면 2%에서 틀리네요ㅜㅜ
#include <iostream> #include <algorithm> using namespace std; #define endl '\n' const int INF = 987654321; int N, M, T; int circle[51][50]; void rotate(int number, int dir, int move) { switch (dir) { case 0: for (int i = 0; i < move; ++i) { for (int j = 1; j <= N; ++j) { if (j % number == 0) { for (int k = M-1; k >= 1; --k) { swap(circle[j][k], circle[j][k - 1]); } } } } break; case 1: for (int i = 0; i < move; ++i) { for (int j = 1; j <= N; ++j) { if (j % number == 0) { for (int k = 0; k < M - 1; ++k) { swap(circle[j][k], circle[j][k + 1]); } } } } break; } } int nearErase() { int copy[51][50]; for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { copy[i][j] = circle[i][j]; } } int count = 0; for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { int pivot = circle[i][j]; if (pivot == INF) continue; if (i == 1) { if (circle[i + 1][j] == pivot) { copy[i + 1][j] = copy[i][j] = INF; count++; } if (circle[i][(j + 1) % M] == pivot) { copy[i][(j + 1) % M] = copy[i][j] = INF; count++; } if (circle[i][(j - 1) % M] == pivot) { copy[i][(j - 1) % M] = copy[i][j] = INF; count++; } } else if (i == N) { if (circle[i - 1][j] == pivot) { copy[i - 1][j] = copy[i][j] = INF; count++; } if (circle[i][(j + 1) % M] == pivot) { copy[i][(j + 1) % M] = copy[i][j] = INF; count++; } if (circle[i][(j - 1) % M] == pivot) { copy[i][(j - 1) % M] = copy[i][j] = INF; count++; } } else { if (circle[i + 1][j] == pivot) { copy[i + 1][j] = copy[i][j] = INF; count++; } if (circle[i - 1][j] == pivot) { copy[i - 1][j] = copy[i][j] = INF; count++; } if (circle[i][(j + 1) % M] == pivot) { copy[i][(j + 1) % M] = copy[i][j] = INF; count++; } if (circle[i][(j - 1) % M] == pivot) { copy[i][(j - 1) % M] = copy[i][j] = INF; count++; } } } } for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { circle[i][j] = copy[i][j]; } } return count; } void changeNumber() { int cnt = 0, sum = 0; for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { if (circle[i][j] != INF) { cnt++; sum += circle[i][j]; } } } for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { if (circle[i][j] != INF) { if (circle[i][j] * cnt > sum) { circle[i][j]--; } else if (circle[i][j] * cnt < sum) { circle[i][j]++; } } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> N >> M >> T; for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { cin >> circle[i][j]; } } for (int i = 0; i < T; ++i) { int x, d, k; cin >> x >> d >> k; rotate(x, d, k); int cnt = nearErase(); if (cnt == 0) { changeNumber(); } } int ans = 0; for (int i = 1; i <= N; ++i) { for (int j = 0; j < M; ++j) { if (circle[i][j] != INF) { ans += circle[i][j]; } } } cout << ans << endl; return 0; }
댓글을 작성하려면
로그인
해야 합니다.
vire3064 4년 전
빠짐없이 구현한 것 같은데 테케는 다맞고 제출하면 2%에서 틀리네요ㅜㅜ