QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#334004#4325. Kraljicecoolplum0 1ms7748kbC++143.9kb2024-02-20 23:05:512024-02-20 23:05:51

Judging History

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

  • [2024-02-20 23:05:51]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7748kb
  • [2024-02-20 23:05:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int MAXN=1025;

int n;
int row[MAXN]={0}, column[MAXN]={0}, ldiagonal[2*MAXN]={0}, rdiagonal[2*MAXN]={0};
int order[MAXN][MAXN];
int k=1;

void add(int x, int y)
{
    order[x][y]=k;
    k=k+1;
    row[x]=row[x]+1;
    column[y]=column[y]+1;
    ldiagonal[x+y]=ldiagonal[x+y]+1;
    rdiagonal[x-y+n]=rdiagonal[x-y+n]+1;

    return;
}

void build3(int x, int y)
{
    if (y==1)
    {
        add(1, 2);
        add(2, 0);
        add(1, 1);
        add(0, 0);
        add(2, 2);
        add(2, 1);
        add(0, 1);
        add(0, 2);
        add(1, 0);

        return;
    }
    if (x==0)
        build3(x, y-2);
    if (y-x==1)
    {
        y=y-1;
        add(x+1, y+2);
        add(x+0, y+1);
        add(x+2, y+1);
        add(x+1, y+1);
        add(x+0, y+2);
        add(x+2, y+0);
        add(x+1, y+0);
        add(x+2, y+2);

        return;
    }
    if ((row[x]+column[y]+ldiagonal[x+y]+rdiagonal[x-y+n])%2==0)
    {
        add(x, y);
        add(x, y+1);
        if ((row[y]+column[x]+ldiagonal[y+x]+rdiagonal[y-x+n])%2==0)
        {
            add(y, x);
            add(y+1, x);
        }
        else
        {
            add(y+1, x);
            add(y, x);
        }
    }
    else
    {
        add(x, y+1);
        add(x, y);
        if ((row[y]+column[x]+ldiagonal[y+x]+rdiagonal[y-x+n])%2==0)
        {
            add(y, x);
            add(y+1, x);
        }
        else
        {
            add(y+1, x);
            add(y, x);
        }
    }
    build3(x+1, y);

    return;
}

void build4(int x, int y)
{
    if (y==2)
    {
        add(0, 1);
        add(1, 3);
        add(0, 2);
        add(1, 0);
        add(1, 1);
        add(2, 3);
        add(0, 3);
        add(2, 0);
        add(2, 1);
        add(2, 2);
        add(3, 0);
        add(3, 2);
        add(3, 1);
        add(3, 3);

        return;
    }
    if (x==0)
        build4(x, y-2);
    if (y-x==1)
    {
        y=y-1;
        add(x+0, y+2);
        add(x+0, y+1);
        add(x+1, y+2);
        add(x+1, y+0);
        add(x+2, y+0);
        add(x+1, y+1);
        add(x+2, y+1);
        add(x+2, y+2);

        return;
    }
    if ((row[x]+column[y]+ldiagonal[x+y]+rdiagonal[x-y+n])%2==0)
    {
        add(x, y);
        add(x, y+1);
        if ((row[y]+column[x]+ldiagonal[y+x]+rdiagonal[y-x+n])%2==0)
        {
            add(y, x);
            add(y+1, x);
        }
        else
        {
            add(y+1, x);
            add(y, x);
        }
    }
    else
    {
        add(x, y+1);
        add(x, y);
        if ((row[y]+column[x]+ldiagonal[y+x]+rdiagonal[y-x+n])%2==0)
        {
            add(y, x);
            add(y+1, x);
        }
        else
        {
            add(y+1, x);
            add(y, x);
        }
    }
    build4(x+1, y);

    return;
}

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

    cin >> n;
    memset(order, 0, sizeof(order));
    if (n<=2)
    {
        cout << 1 << '\n';
        cout << 1 << ' ' << 1 << '\n';
    }
    else if (n%2==1)
    {
        build3(0, n-2);
        pair<int, int> answer[n*n];
        for (int i=0; i<n; i++)
            for (int j=0; j<n; j++)
                answer[order[i][j]-1]={i+1, j+1};
        cout << n*n << '\n';
        for (int i=0; i<n*n; i++)
            cout << answer[i].first << ' ' << answer[i].second << '\n';
    }
    else
    {
        build4(0, n-2);
        pair<int, int> answer[n*n-2];
        for (int i=0; i<n; i++)
            for (int j=0; j<n; j++)
                if (order[i][j]!=0)
                    answer[order[i][j]-1]={i+1, j+1};
        cout << n*n-2 << '\n';
        for (int i=0; i<n*n-2; i++)
            cout << answer[i].first << ' ' << answer[i].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: 1ms
memory: 7740kb

input:

1

output:

1
1 1

result:

ok 1 queen(s)

Test #2:

score: 0
Accepted
time: 1ms
memory: 7668kb

input:

2

output:

1
1 1

result:

ok 1 queen(s)

Test #3:

score: 0
Accepted
time: 1ms
memory: 7676kb

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: 7720kb

input:

4

output:

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

result:

ok 14 queen(s)

Test #5:

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

input:

5

output:

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

result:

ok 25 queen(s)

Test #6:

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

input:

6

output:

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

result:

ok 34 queen(s)

Test #7:

score: 0
Accepted
time: 1ms
memory: 7688kb

input:

7

output:

49
2 3
3 1
2 2
1 1
3 3
3 2
1 2
1 3
2 1
1 5
1 4
4 1
5 1
2 4
2 5
5 2
4 2
4 5
3 4
5 4
4 4
3 5
5 3
4 3
5 5
1 7
1 6
6 1
7 1
2 6
2 7
7 2
6 2
3 7
3 6
6 3
7 3
4 6
4 7
7 4
6 4
6 7
5 6
7 6
6 6
5 7
7 5
6 5
7 7

result:

ok 49 queen(s)

Test #8:

score: -6
Wrong Answer
time: 1ms
memory: 7672kb

input:

8

output:

62
1 2
2 4
1 3
2 1
2 2
3 4
1 4
3 1
3 2
3 3
4 1
4 3
4 2
4 4
1 5
1 6
6 1
5 1
2 6
2 5
6 2
5 2
3 6
3 5
6 3
5 3
4 6
4 5
5 6
5 4
6 4
5 5
6 5
6 6
1 7
1 8
8 1
7 1
2 8
2 7
8 2
7 2
3 8
3 7
8 3
7 3
4 7
4 8
8 4
7 4
5 8
5 7
8 5
7 5
6 8
6 7
7 8
7 6
8 6
7 7
8 7
8 8

result:

wrong answer the cell (8, 5) is attacking by 15 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%