#include <iostream>
#include<vector>
#include<map>
#include<queue>
#define int long long
using namespace std;
map<vector<int>, bool> mp;
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
vector<int> a(n), b(n), c(n, 0);
for (int i = 0; i < n; ++i)
cin >> a[i] >> b[i];
mp[a] = 1;
queue<vector<int>> q;
q.push(a);
while(!q.empty()){
auto x = q.front(); q.pop();
bool ok = 1;
for(int i = 0; i < n; ++i) ok &= (x[i] == b[i]);
if(ok) {cout << "Yes"; exit(0);}
for(int i = 0; i < n; ++i)
for(int j = 1; (2 * j) <= x[i]; ++j){
x[i] -= (2 * j), x[(i + 1) % n] += j;
if(mp.find(x) == mp.end()) mp[x] = 1, q.push(x);
x[i] += (2 * j), x[(i + 1) % n] -= j;
}
}
cout << "No";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |