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>
using namespace std;
const int N = 105;
vector<pair<int, int>> path;
bool seen[N][N];
void recur(int x, int y, int a, int b, int c, int d){
if (x < 0 or y < 0) return;
if (a == 0 and b == 0 and c == 0 and d == 0){
if (x == 0 and y == 0){
for (auto [x, y] : path)
cout << x << " " << y << endl;
exit(0);
}
return;
}
if (seen[x][y]) return;
path.push_back({x, y});
if (a > 0){
recur(x + 1, y, a - 1, b, c, d);
recur(x - 1, y, a - 1, b, c, d);
}
if (b > 0){
recur(x, y + 1, a, b - 1, c, d);
recur(x, y - 1, a, b - 1, c, d);
}
if (c > 0){
recur(x + 1, y + 1, a, b, c - 1, d);
recur(x - 1, y - 1, a, b, c - 1, d);
}
if (d > 0){
recur(x + 1, y - 1, a, b, c, d - 1);
recur(x - 1, y + 1, a, b, c, d - 1);
}
path.pop_back();
}
int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == 0 and b == 0){
vector<pair<int, int>> vec;
int x = 0, y = 0;
vec.push_back({0, 0});
for (int i = 0; i < c / 2; i ++){
x++, y++;
vec.push_back({x, y});
}
for (int i = 0; i < d / 2; i ++){
x--, y++;
vec.push_back({x, y});
}
for (int i = 0; i < c / 2; i ++){
x--, y--;
vec.push_back({x, y});
}
for (int i = 0; i < d / 2; i ++){
x++, y--;
vec.push_back({x, y});
}
vec.pop_back();
for (auto [x, y] : vec)
cout << x << " " << y << endl;
return 0;
}
if (c == 0 and d == 0){
vector<pair<int, int>> vec;
int x = 0, y = 0;
vec.push_back({0, 0});
for (int i = 0; i < a / 2; i ++){
x++;
vec.push_back({x, y});
}
for (int i = 0; i < b / 2; i ++){
y++;
vec.push_back({x, y});
}
for (int i = 0; i < a / 2; i ++){
x--;
vec.push_back({x, y});
}
for (int i = 0; i < b / 2; i ++){
y--;
vec.push_back({x, y});
}
vec.pop_back();
for (auto [x, y] : vec)
cout << x << " " << y << endl;
return 0;
}
recur(0, 0, a, b, c, d);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |