개미가 부딪히고 방향을 바꾸는 걸 다르게 생각해보면 통과한다고 볼 수 있다. 그러면 최대 길이를 구할 수 있는데 마지막 개미의 번호를 구하는 게 문제였다. 느낌 상 중간에 있는 개미가 가장 늦게 떨어질 것 같은데 그러면 R R R인 경우에는 어떻게 해야 하나 싶고.
고민하다가 이 분 글 보고 참고해서 문제 풀었다.
codersbrunch.blogspot.com/2017/02/6612-andrew-ant.html
개미가 통과한다고 가정하면 L 개미들이 p개 있으면 가장 마지막에 떨어지는 개미는 p 위치에 있어야 하기 때문에 이 위치 개미를 출력하는 방식으로 구현했는데 음.. 잘 이해를 못하겠다. 이까지 하고 패스해야겠다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int l, a;
while (cin >> l >> a)
{
vector<int> v(a);
int ml = -1, mr = -1, p = 0;
for (int i = 0; i < a; i++)
{
string s;
cin >> v[i] >> s;
if (s == "R")
mr = max(mr, l - v[i]);
else
{
ml = max(ml, v[i]);
p++;
}
}
sort(all(v));
cout << "The last ant will fall down in " << max(ml, mr) << " seconds - started at " << ((ml < mr) ? v[p] : v[p - 1]);
if (ml == mr)
cout << " and " << v[p] << ".\n";
else
cout << ".\n";
}
return 0;
}
'백준' 카테고리의 다른 글
11058 크리보드 (0) | 2021.01.10 |
---|---|
12738 가장 긴 증가하는 부분 수열 3 (0) | 2021.01.10 |
12026 BOJ 거리 (0) | 2020.12.28 |
[10774] 저지 (0) | 2020.12.23 |
1251 단어 나누기 [미완] (0) | 2020.12.14 |