QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#396714 | #4325. Kraljice | MODDI | 0 | 2ms | 3608kb | C++14 | 1.6kb | 2024-04-23 04:30:05 | 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;
}
Details
Tip: Click on the bar to expand more detailed information
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%