QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#73516#4884. Battleship: New Rulesaurelion_solWA 2ms3308kbC++142.9kb2023-01-25 15:02:212023-01-25 15:02:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-25 15:02:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3308kb
  • [2023-01-25 15:02:21]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

void answer(int x, int y) {
    if (x >= 0 || y >= 0) {
        x++, y++;
    }
    cout << "! " << x << " " << y << endl;
    int ans;
    cin >> ans;
    if (ans != 1) {
        exit(0);
    }
}

vector<vector<int>> cache;

int ask(int x, int y) {
    if (x >= (int)cache.size() || y >= (int)cache.size() || x < 0 || y < 0) {
        return 0;
    }
    cout << "? " << x + 1 << " " << y + 1 << endl;
    int ans;
    cin >> ans;
    if (ans == -1) {
        exit(0);
    }
    cache[x][y] = ans;
    return ans;
}

vector<vector<bool>> used;

void color4(int x, int y) {
    for (int dx = 0; dx < 2; dx++) {
        for (int dy = 0; dy < 2; dy++) {
            used[x + dx][y + dy] = true;
        }
    }
}

bool upd(int x, int y) {
    bool res = true;
    for (int dx = 0; dx < 2; dx++) {
        for (int dy = 0; dy < 2; dy++) {
            if (ask(x - dx, y - dy) == 1) {
                color4(x - dx, y - dy);
                res = false;
            }
        }
    }
    return res;
}

pair<int, int> func(int x1, int y1, int x2, int y2) {
    if (x2 - x1 == 1 && y2 - y1 == 1) {
        return make_pair(x1, y1);
    }
    tuple<int, int, int, int> r1, r2;
    if (x2 - x1 >= y2 - y1) {
        int mid = (x1 + x2) / 2;
        for (int i = y1; i < y2; i++) {
            if (upd(mid, i)) {
                return make_pair(mid, i);
            }
        }
        r1 = make_tuple(x1, y1, mid, y2);
        r2 = make_tuple(mid + 1, y1, x2, y2);
    } else {
        int mid = (y1 + y2) / 2;
        for (int i = x1; i < x2; i++) {
            if (upd(i, mid)) {
                return make_pair(i, mid);
            }
        }
        r1 = make_tuple(x1, y1, x2, mid);
        r2 = make_tuple(x1, mid + 1, x2, y2);
    }
    int s1 = 0;
    for (int i = get<0>(r1); i < get<2>(r1); i++) {
        for (int j = get<1>(r1); j < get<3>(r1); j++) {
            if (!used[i][j]) {
                s1++;
            }
        }
    }
    if (s1 % 2 == 1) {
        return func(get<0>(r1), get<1>(r1), get<2>(r1), get<3>(r1));
    } else {
        return func(get<0>(r2), get<1>(r2), get<2>(r2), get<3>(r2));
    }
}

void solve(int n) {
    used.clear();
    used.reserve(n + 1);
    for (int i = 0; i < n + 1; i++) {
        used.emplace_back(vector<bool>(n + 1, false));
    }
    pair<int, int> t = func(0, 0, n + 1, n + 1);
    answer(t.first - 1, t.second - 1);
}

void solve_full(int n) {
    if (n % 2 == 1) {
        answer(-1, -1);
        return;
    }
    cache.clear();
    cache.reserve(n);
    for (int i = 0; i < n; i++) {
        cache.emplace_back(vector<int>(n, -1));
    }
    solve(n);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
	if(t!=100)exit(0);
    while (t--) {
        int n;
        cin >> n;
        solve_full(n);
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3308kb

input:

2
3

output:


result:

wrong output format Unexpected end of file - int32 expected (test case 1)