본문 바로가기

백준

10158 개미

 

처음에는 그냥 그대로 구현하면 되지 않을까? 싶었는데 t가 엄청 큰 수라 터지고. 

그 다음은 반복되는 게 있을테니 그걸 구해볼까 싶었는데 이것도 4만 * 4만이라 터진다..

 

결국 고민하다가 다른 사람 풀이를 찾아봤다. 와.... x축과 y축을 나눠서 생각하는구나. 신기하다. 

 

#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>
#include <stdio.h>
#include <math.h>

#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() {
    i64 w, h, p, q, t;
    scanf("%lld %lld %lld %lld %lld", &w, &h, &p, &q, &t);
    
    
    i64 ansX, ansY;
    if (((p + t) / w) % 2 == 0)
        ansX = (p + t) % w;
    else
        ansX = w - (p + t) % w;
    
    if (((q + t) / h) % 2 == 0)
        ansY = (q + t) % h;
    else
        ansY = h - (q + t) % h;
    
    printf("%lld %lld\n", ansX, ansY);
    
    return 0;
}

'백준' 카테고리의 다른 글

제 3회 소프트콘  (1) 2021.08.28
11558 The Game of Death  (0) 2021.08.28
3048 개미  (0) 2021.08.16
2960 에라토스테네스의 체  (0) 2021.08.16
1907 탄소 화합물  (0) 2021.08.08