QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396714#4325. KraljiceMODDI0 2ms3608kbC++141.6kb2024-04-23 04:30:052024-04-23 04:30:05

Judging History

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

  • [2024-04-23 04:30:05]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3608kb
  • [2024-04-23 04:30:05]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
int n,odg;
vector<pair<int,int> > kako;
map<vector<vector<int> > ,bool> visited;
 
void f(vector<vector<int> > v,vector<pair<int,int> > redosled)
{
    //if (visited[v]) return;
    if (odg<redosled.size())
    {
        odg=redosled.size();
        kako=redosled;
    }
 
    int k=redosled.size();
    redosled.push_back({0,0});
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (v[i][j]==0)
            {
                v[i][j]=2;
                for (int x=0;x<n;x++)
                    for (int y=0;y<n;y++)
                    if (x==i || y==j || x+y==i+j || x-y==i-j)
                {
                    if (v[x][y]==1) v[x][y]=0;
                    else if (v[x][y]==0) v[x][y]=1;
                }
                redosled[k]={i,j};
                f(v,redosled);
 
                for (int x=0;x<n;x++)
                    for (int y=0;y<n;y++)
                    if (x==i || y==j || x+y==i+j || x-y==i-j)
                {
                    if (v[x][y]==1) v[x][y]=0;
                    else if (v[x][y]==0) v[x][y]=1;
                }
                v[i][j]=0;
            }
        }
    }
    //visited[v]=true;
}
 
int main()
{
    cin>>n;
    if (n==15)
    {
        //cout<<
    }
 
    vector<vector<int> > v(n*n+2);
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++) v[i].push_back(0);
 
    f(v,{});
    cout<<odg<<endl;
    for (int i=0;i<kako.size();i++) cout<<kako[i].first+1<<" "<<kako[i].second+1<<endl;
 
    return 0;
}

详细

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 6
Accepted
time: 1ms
memory: 3608kb

input:

1

output:

1
1 1

result:

ok 1 queen(s)

Test #2:

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

input:

2

output:

1
1 1

result:

ok 1 queen(s)

Test #3:

score: 6
Accepted
time: 2ms
memory: 3592kb

input:

3

output:

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

result:

ok 9 queen(s)

Test #4:

score: 0
Time Limit Exceeded

input:

4

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%