이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = INT_MAX;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int MAX = 1000010;
int n;
int init[MAX], target[MAX];
bool res;
set<vi> vis;
void dfs(vi arr){
vis.insert(arr);
bool ok = 1;
FOR(i, 0, n - 1, 1){
if(arr[i] != target[i]) ok = 0;
}
if(ok){
res = 1;
return;
}
FOR(i, 0, n - 1, 1){
int ii = (i + 1) % n;
if(arr[i] >= 2){
arr[i] -= 2;
arr[ii] += 1;
if(vis.find(arr) == vis.end()) dfs(arr);
arr[i] += 2;
arr[ii] -= 1;
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
FOR(i, 0, n - 1, 1){
cin>>init[i]>>target[i];
}
vi arr;
FOR(i, 0, n - 1, 1){
arr.pb(init[i]);
}
dfs(arr);
if(res) cout<<"Yes"<<'\n';
else cout<<"No"<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |