| Task: | Chess board tour |
| Sender: | aalto26im_018 |
| Submission time: | 2026-11-02 17:18:52 +0200 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:11:18: error: expected ';' before 'if'
11 | cin >> n >> m
| ^
| ;
12 |
13 | if ((n % 2 != 0) && (m % 2 != 0)) {
| ~~Code
#include <iostream>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m
if ((n % 2 != 0) && (m % 2 != 0)) {
cout << -1 << "\n";
return 0;
}
string ans;
ans.reserve(n * m);
if (m % 2 == 0) {
ans.append(n - 1, 'D');
for (int c = 2; c <= m; ++c) {
ans.push_back('R');
if (c < m) {
if (c % 2 == 0) {
ans.append(n - 2, 'U');
} else {
ans.append(n - 2, 'D');
}
} else {
ans.append(n - 1, 'U');
}
}
ans.append(m - 1, 'L');
} else {
ans.append(m - 1, 'R');
for (int r = 2; r <= n; ++r) {
ans.push_back('D');
if (r < n) {
if (r % 2 == 0) {
ans.append(m - 2, 'L');
} else {
ans.append(m - 2, 'R');
}
} else {
ans.append(m - 1, 'L');
}
}
ans.append(n - 1, 'U');
}
cout << ans << "\n";
}