문제 링크
두 개로 분리된 위 아래 조각이 중력에 의해서 합쳐진다고 가정했을 때 빈틈 없이 합쳐질 수 있는가를 판단하는 문제
조각이 두 개로만 분리됬다고 보장이 되니까 위와 아래 사이 공간이 모두 같은 칸이 있으면 빈틈 없이 합쳐질 수 있다.
한 번 순회하면서 빈 공간이 다른 공간이 있는 지 보면 된다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000
int t;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
for (int tc = 1; tc <= t; tc++){
int n; cin >> n;
vector<int> v;
for (int i = 1; i <= n; ++i) {
int a, b;
cin >> a >> b;
v.push_back(a-b);
}
bool flag = true;
for (int i = 1; i < v.size(); ++i)
if (v[i] != v[i-1]) { flag = false; break; }
if (flag) cout << "yes" << "\n";
else cout << "no" << "\n";
if (tc < t) cout << '\n';
}
}