1번 선수가 4번 타자인 걸 고정시키고 brute force로 모든 순서를 구한 뒤 규칙에 맞게 게임을 하면 된다.
list에서 erase 함수를 사용하고 다음 노드를 가르킬 때는 iterator를 증가시키면 안된다는 것을 놓쳐서 조금 헤맸다.
구현 문제 극혐이다!
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
int order[9];
int arr[50][9];
int n, ans = 0;
void input() {
fastio;
cin >> n;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < 9; ++j) {
cin >> arr[i][j];
}
}
}
void hit(int num, int& score, list<int>& base) {
if(num == 4) {
score += base.size()+1;
base.clear();
return ;
}
for(auto it = base.begin(); it != base.end();) {
if((*it) + num >= 4) {
it = base.erase(it);
score++;
} else {
(*it) += num;
++it;
}
}
base.push_back(num);
}
void play() {
list<int> base;
int score = 0, out = 0, turn = 0;
for(int i = 0; i < n; ++i) {
while(out < 3) {
while(1) {
if(arr[i][order[turn]]) hit(arr[i][order[turn]], score, base);
else out++;
turn++;
if(turn == 9) turn = 0;
if(out >= 3) break;
}
}
// 이닝 끝
base.clear();
out = 0;
}
ans = max(ans, score);
}
void d(int idx, int visited) {
if(idx == 9 ) {
play();
return ;
}
for(int i = 0; i < 9; ++i) {
if(visited & (1 << i)) continue;
order[idx] = i;
if(idx+1 == 3) d(idx+2, visited | (1 << i));
else d(idx+1, visited | (1 << i));
}
}
int main() {
input();
order[3] = 0;
d(0, 1);
cout << ans;
}
백준 2143 두 배열의 합 혼내주기 (0) | 2021.08.01 |
---|---|
백준 19598 최소 회의실 개수 혼내주기 (0) | 2021.08.01 |
백준 11000 강의실 배정 혼내주기 (0) | 2021.08.01 |
백준 5557 1학년 혼내주기 (0) | 2021.08.01 |
백준 20440 🎵니가 싫어 싫어 너무 싫어 싫어 오지 마 내게 찝쩍대지마🎵 - 1 혼내주기 (0) | 2021.08.01 |
댓글 영역