Created
January 27, 2020 11:29
백준 문제풀이
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define pii pair<int, int> | |
const int MAX = 1<<16; | |
const int INF = 1000000000; | |
int N, M; | |
vector<pii> arr; | |
int main(){ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); | |
cin >> N; | |
for (int i = 0; i < N; ++i){ | |
int y, r; | |
cin >> y >> r; | |
arr.push_back(pii(y,r)); | |
} | |
cin>>M; | |
for (int i = 0; i < M; ++i){ | |
int y, x; | |
int Y = -1; | |
int X = -2; | |
// 중간 년도 값들의 최대 저장 | |
int Between = -1; | |
bool ValueY = false; | |
bool ValueX = false; | |
// 모든 년도 값들이 다 있는지 체크 | |
bool NOTALL = false; | |
int cnt = 0; | |
cin >> y >> x; | |
for (int j = 0; j < arr.size(); ++j){ | |
if(arr[j].first < y) continue; | |
else if(arr[j].first == y){ | |
Y = arr[j].second; | |
ValueY = true; | |
} | |
else if(arr[j].first > y && arr[j].first < x){ | |
Between = max(Between,arr[j].second); | |
cnt++; | |
} | |
else if(arr[j].first == x){ | |
X = arr[j].second; | |
ValueX = true; | |
break; | |
} | |
else break; | |
} | |
if(cnt<x-y-1) NOTALL = true; | |
// 애초에 조건 만족 안하는 경우 | |
if((ValueX&&Between>=X) || (ValueY&&Between>=Y) || (ValueX&&ValueY&&X>Y)){ | |
cout << "false" << '\n'; | |
continue; | |
} | |
// x,y 가 연속된 년도인 경우 | |
if(y+1==x){ | |
// X==Y==1 인 경우도 걸러짐..! | |
if(ValueX&&ValueY) cout << "true" << '\n'; | |
else cout << "maybe" << '\n'; | |
continue; | |
} | |
// 아래는 x,y 가 연속되지 않은 경우만 남음 | |
// x나 y년도 값이 1(최소) 인경우 | |
if(X==1 || Y==1){ | |
cout << "false" << '\n'; | |
continue; | |
} | |
// 모르는 값이 있는 경우 | |
if(NOTALL||!ValueX||!ValueY){ | |
cout << "maybe" << '\n'; | |
continue; | |
} | |
// 중간에 빠진 년도 있는경우 | |
if(NOTALL){ | |
cout << "maybe" << '\n'; | |
continue; | |
} | |
cout << "true" << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment