QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#334012#4325. Kraljicelukap_0 0ms3756kbC++142.8kb2024-02-20 23:18:442024-02-20 23:18:44

Judging History

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

  • [2024-02-20 23:18:44]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3756kb
  • [2024-02-20 23:18:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e3 + 500;

int n;
vector<pair<int, int> > rj;
int mat[MAXN][MAXN];

void play (int x, int y) {
    rj.push_back ({x, y});
    mat[x][y] = 1;
}

void tri () {
    play (2, 3);
    play (3, 1);
    play (2, 2);
    play (1, 1);
    play (3, 3);
    play (3, 2);
    play (1, 2);
    play (1, 3);
    play (2, 1);
}

void cetiri () {
    play (1, 1);
    play (2, 4);
    play (1, 4);
    play (2, 1);
    play (3, 1);
    play (4, 1);
    play (4, 4);
    play (3, 4);
    play (1, 2);
    play (2, 2);
    play (4, 3);
    play (2, 3);
    play (3, 3);
    play (3, 2);
}

void par (int x) {
    play (x - 2, x);
    play (x - 2, x - 1);
    play (x - 1, x);
    play (x - 1, x - 2);
    play (x, x - 2);
    play (x - 1, x - 1);
    play (x, x - 1);
    play (x, x);
}

void nepar (int x) {
    play (x - 1, x);
    play (x - 2, x - 1);
    play (x, x - 1);
    play (x - 1, x - 1);
    play (x - 2, x);
    play (x, x - 2);
    play (x - 1, x - 2);
    play (x, x);
}

int provjeri (int x, int y) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += mat[i][y];
        sum += mat[x][i];
    }

    int nx = x, ny = y;
    while (nx > 0 && ny > 0) {
        nx--;
        ny--;
        sum += mat[nx][ny];
    }
    nx = x, ny = y;
    while (nx <= n && ny <= n) {
        nx++;
        ny++;
        sum += mat[nx][ny];
    }
    nx = x, ny = y;
    while (nx <= n && ny > 0) {
        nx++;
        ny--;
        sum += mat[nx][ny];
    }
    nx = x, ny = y;
    while (nx > 0 && ny <= n) {
        nx--;
        ny++;
        sum += mat[nx][ny];
    }

//    cout << "AAAAA " << x << ' ' << y << ' ' << sum << "\n";
    return sum % 2;
}

void solve (int x) {
    if (x == 3) {
        tri ();
        return;
    }
    if (x == 4) {
        cetiri ();
        return;
    }

    solve (x - 2);

    for (int i = 0; i < x - 3; i++) {
        if (provjeri (x - 1, i + 1) == 0) {
            play (x - 1, i + 1);
            play (x, i + 1);
        }
        else {
            play (x, i + 1);
            play (x - 1, i + 1);
        }

        if (provjeri (i + 1, x - 1) == 0) {
            play (i + 1, x - 1);
            play (i + 1, x);
        }
        else {
            play (i + 1, x);
            play (i + 1, x - 1);
        }
    }

    if (x % 2 == 0) par (x);
    else nepar (x);
}

int main () {
    ios_base::sync_with_stdio (false);
    cin.tie (0);

    cin >> n;

    if (n == 1) {
        play (1, 1);
    }
    else if (n == 2) {
        play (1, 1);
    }
    else solve (n);

    cout << rj.size () << "\n";
    for (auto it: rj) cout << it.first << ' ' << it.second << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 0ms
memory: 3748kb

input:

1

output:

1
1 1

result:

ok 1 queen(s)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

2

output:

1
1 1

result:

ok 1 queen(s)

Test #3:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

3

output:

9
2 3
3 1
2 2
1 1
3 3
3 2
1 2
1 3
2 1

result:

ok 9 queen(s)

Test #4:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

4

output:

14
1 1
2 4
1 4
2 1
3 1
4 1
4 4
3 4
1 2
2 2
4 3
2 3
3 3
3 2

result:

ok 14 queen(s)

Test #5:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

5

output:

25
2 3
3 1
2 2
1 1
3 3
3 2
1 2
1 3
2 1
5 1
4 1
1 4
1 5
4 2
5 2
2 5
2 4
4 5
3 4
5 4
4 4
3 5
5 3
4 3
5 5

result:

ok 25 queen(s)

Test #6:

score: -6
Wrong Answer
time: 0ms
memory: 3724kb

input:

6

output:

34
1 1
2 4
1 4
2 1
3 1
4 1
4 4
3 4
1 2
2 2
4 3
2 3
3 3
3 2
5 1
6 1
1 5
1 6
6 2
5 2
2 6
2 5
6 3
5 3
3 6
3 5
4 6
4 5
5 6
5 4
6 4
5 5
6 5
6 6

result:

wrong answer the cell (6, 1) is attacking by 7 queen(s)

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%