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 <iostream>
#include <vector>
using namespace std;
typedef vector <vector <bool>> matrix;
int n;
vector <string> rot;
/*
0 = intersect
1 = same
2 = parallel
*/
inline const matrix cm(vector <pair <int, int>> lamps = {}) {
matrix m(n, vector<bool>(n, false));
for (auto &p : lamps) m[p.first][p.second] = true;
return m;
}
short ask(short x1, short y1, short x2, short y2) {
cout << '?';
for (auto &i : cm({{x1, y1}, {x2, y2}})) {
cout << '\n';
for (bool &&j : i) cout << j;
}
cout << endl;
int x;
cin >> x;
if (x == 2 * n) return 2;
if (x == n) return 1;
return 0;
}
void answer(const matrix &m) {
cout << '!';
for (auto &i : m) {
cout << '\n';
for (bool &&j : i) cout << j;
}
exit(0);
}
char rotof(short x, short y) {
if (rot[x][y] == '.') {
for (int i = 0; i < n; i++) {
if (rot[x][i] != '.') {
if (ask(x, i, x, y)) return rot[x][y] = rot[x][i];
return rot[x][y] = rot[x][i] == 'V' ? 'H' : 'V';
}
if (rot[i][y] != '.') {
if (ask(i, y, x, y)) return rot[x][y] = rot[i][y];
return rot[x][y] = rot[i][y] == 'V' ? 'H' : 'V';
}
}
}
return rot[x][y];
}
void ansvert() {
matrix m = cm();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (rot[j][i] == 'V') {
m[j][i] = true;
break;
}
}
}
answer(m);
}
void anshor() {
matrix m = cm();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (rot[i][j] == 'H') {
m[i][j] = true;
break;
}
}
}
answer(m);
}
signed main() {
cin >> n;
rot = vector(n, string(n, '.'));
short ans = ask(0, 0, 0, 1);
if (ans == 2) rot[0][0] = rot[0][1] = 'V';
else if (ans == 1) rot[0][0] = rot[0][1] = 'H';
else {
ans = ask(0, 0, 0, 2);
if (ans == 2) {
rot[0][1] = 'H';
rot[0][0] = rot[0][2] = 'V';
}
else if (ans == 1) {
rot[0][1] = 'V';
rot[0][0] = rot[0][2] = 'H';
}
else if (ask(0, 1, 0, 2) == 2) {
rot[0][0] = 'H';
rot[0][1] = rot[0][2] = 'V';
}
else {
rot[0][0] = 'V';
rot[0][1] = rot[0][2] = 'H';
}
}
for (int i = 0, j = 1; i < n; i++) {
if (rotof(0, i) == 'H') {
while (j < n && rotof(j, i) == 'H') j++;
if (j == n) anshor();
}
}
ansvert();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |