记录编号 559958 评测结果 AAAAAAAAAA
题目名称 亡羊补牢,未为迟也 最终得分 100
用户昵称 Gravatar遥时_彼方 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2021-03-31 18:47:23 内存使用 0.00 MiB
显示代码纯文本
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
int nc,mc;
int n[21][21];
int mn,mj;
void dg(int x,int y,int num,int em)
{
    int l[10][2],lj=0;
    int xt=x,yt=y;
    if(xt+1>nc) 
    {
        xt=1;
        yt++;
        if(yt<=mc) dg(xt,yt,num,em);
    }
    else dg(xt+1,yt,num,em);
    n[x][y]++;
    l[++lj][0]=x;
    l[lj][1]=y;
    num++;
    if(n[x][y]==1) em--;
    if(x-2>0&&y+1<=mc)
    {
        if(!n[x-2][y+1]) em--;
        n[x-2][y+1]++;
        l[++lj][0]=x-2;
        l[lj][1]=y+1;
    }
    if(x-1>0&&y+2<=mc)
    {
        if(!n[x-1][y+2]) em--;
        n[x-1][y+2]++;
        l[++lj][0]=x-1;
        l[lj][1]=y+2;
    }
    if(x+1<=nc&&y+2<=mc)
    {
        if(!n[x+1][y+2]) em--;
        n[x+1][y+2]++;
        l[++lj][0]=x+1;
        l[lj][1]=y+2;
    }
    if(x+2<=nc&&y+1<=mc)
    {
        if(!n[x+2][y+1]) em--;
        n[x+2][y+1]++;
        l[++lj][0]=x+2;
        l[lj][1]=y+1;
    }
    if(x+1<=nc&&y-2>0)
    {
        if(!n[x+1][y-2]) em--;
        n[x+1][y-2]++;
        l[++lj][0]=x+1;
        l[lj][1]=y-2;
    }
    if(x-1>0&&y-2>0)
    {
        if(!n[x-1][y-2]) em--;
        n[x-1][y-2]++;
        l[++lj][0]=x-1;
        l[lj][1]=y-2;
    }
    if(x-2>0&&y-1>0)
    {
        if(!n[x-2][y-1]) em--;
        n[x-2][y-1]++;
        l[++lj][0]=x-2;
        l[lj][1]=y-1;
    }
    if(x+2<=nc&&y-1>0)
    {
        if(!n[x+2][y-1]) em--;
        n[x+2][y-1]++;
        l[++lj][0]=x+2;
        l[lj][1]=y-1;
    }
//    cout<<x<<" "<<y<<" "<<num<<" "<<em<<" "<<mn<<" "<<mj<<endl;
    if(em==0) 
    {
//        cout<<x<<" "<<y<<" "<<num<<" "<<em<<" "<<mn<<" "<<mj<<endl;
        if(num<mn) 
        {
            mn=num;
            mj=1;
        }
        else if(num==mn) mj++;
    }
    else 
    {
        if(x+1>nc) 
        {
            x=1;
            y++;
            if(y<=mc) dg(x,y,num,em);
        }
        else dg(x+1,y,num,em);
    }
    for(int i=1;i<=lj;i++) n[l[i][0]][l[i][1]]--;
    return;
}
int main()
{
    freopen("secretnum.in","r",stdin);
	freopen("secretnum.out","w",stdout);
	cin>>nc>>mc;
	mn=10000;
	dg(1,1,0,nc*mc);
	cout<<mn<<" "<<mj<<endl;
    return 0;
}