페이지

3221번: mravi

https://www.acmicpc.net/problem/3221


$O(n\lg n)$

개미가 위치 x, t초 동안 오른쪽으로 d만큼 이동하면
l-abs((x+d)%(2*l)-l)
에 위치하게 된다.
모든 개미의 최종 위치를 구하고 정렬하면 끝.

#include<cstdio>
#include<algorithm>
using namespace std;
int l, t, n, a[70000], x;
char c;
int main() {
    scanf("%d%d%d", &l, &t, &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %c", &x, &c);
        a[i] = l - abs(abs(c == 'L' ? x - t : x + t) % (2 * l) - l);
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) printf("%d ", a[i]);
    return 0;
}

댓글 없음 :

댓글 쓰기