This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;
using namespace std;
ll ops = 0;
vector<int> wanted;
vector<int> v;
int main() {
ll n;
cin >> n;
wanted.resize(n);
v.resize(n);
rep(i, 0, n) {
cin >> v[i] >> wanted[i];
}
queue<vector<int>> q;
q.push(v);
string res = "No";
map<vector<int>, bool> mp;
mp[v] = 1;
while (!q.empty()) {
if (q.front() == wanted) {
res = "Yes";
}
rep(i, 0, q.front().size()) {
vector<int> nxt = q.front();
rep(j, 0, 3) {
if (nxt[i] - j * 2 >= 0) {
nxt[i] -= j * 2;
nxt[(i + 1) % nxt.size()] += j;
if (!mp[nxt]) {
q.push(nxt);
mp[nxt] = 1;
}
}
}
}
q.pop();
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |