QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#334345#4325. Kraljiceivanj0 0ms3736kbC++204.6kb2024-02-21 19:23:072024-02-21 19:23:07

Judging History

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

  • [2024-02-21 19:23:07]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3736kb
  • [2024-02-21 19:23:07]
  • 提交

answer

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

const int MAXN=1030;

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;
    }
    //cout << "x y " << x+1 << ' ' << y+1 << '\n';
    //cout << row[x]+column[y]+ldiagonal[x+y]+rdiagonal[x-y+n] << '\n';
    //cout << row[x]+column[y+1]+ldiagonal[x+y+1]+rdiagonal[x-y-1+n] << '\n';
    if ((row[x]+column[y]+ldiagonal[x+y]+rdiagonal[x-y+n])%2==0)
    {
        add(x, y);
        add(x, y+1);
        //cout << "x y " << y+1 << ' ' << x+1 << '\n';
        //cout << row[y]+column[x]+ldiagonal[x+y]+rdiagonal[y-x+n] << '\n';
        //cout << row[y]+column[x+1]+ldiagonal[x+y+1]+rdiagonal[y-x-1+n] << '\n';
        if ((row[y+1]+column[x]+ldiagonal[y+1+x]+rdiagonal[y+1-x+n])%2==0)
        {
            add(y+1, x);
            add(y, x);
        }
        else
        {
            add(y, x);
            add(y+1, x);
        }
    }
    else
    {
        add(x, y+1);
        add(x, y);
        //cout << "x y " << y+1 << ' ' << x+1 << '\n';
        //cout << row[y]+column[x]+ldiagonal[x+y]+rdiagonal[y-x+n] << '\n';
        //cout << row[y]+column[x+1]+ldiagonal[x+y+1]+rdiagonal[y-x-1+n] << '\n';
        if ((row[y+1]+column[x]+ldiagonal[y+1+x]+rdiagonal[y+1-x+n])%2==0)
        {
            add(y+1, x);
            add(y, x);
        }
        else
        {
            add(y, x);
            add(y+1, x);
        }
    }
    build4(x+1, y);

    return;
}

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

    cin >> n;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            order[i][j]=0;
    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: 0ms
memory: 3640kb

input:

1

output:

1
1 1

result:

ok 1 queen(s)

Test #2:

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

input:

2

output:

1
1 1

result:

ok 1 queen(s)

Test #3:

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

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

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

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

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: 0ms
memory: 3684kb

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: 0ms
memory: 3736kb

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%