백준
16114 화살표 연산자
불타는강정
2021. 9. 14. 14:15
계속 틀려서 직접 코드까지 짜봤는데 그래도 못 찾았다.. 결국 다른 분 도움 받아서 해결했다.
예외 케이스 처리
1. n이 1이고 x가 양수인 경우 -> 마이너스로 생각한다 (-3)
2. n이 1이고 z가 음수인 경우 -> - (-3)으로 생각해 양수가 된다.
이 두 케이스를 빼먹어서 틀렸다.
#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() {
int x, n;
scanf("%d %d", &x, &n);
if (x < 0 && n == 1) {
printf("INFINITE\n");
return 0;
}
if (x >= 0 && n == 1) {
printf("0\n");
return 0;
}
if (n % 2 == 1) {
printf("ERROR\n");
return 0;
}
if (x <= 0) {
printf("0\n");
return 0;
}
if (n == 0) {
printf("INFINITE\n");
return 0;
}
n = n / 2;
printf("%d\n", (x + n - 1) / n - 1);
return 0;
}