//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "对抗搜索+Alpha-Beta  (一双木棋chess TLE)": {
        "prefix": "acm-7.3最大分数",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=13,inf=2e9;",
            "int n,m,cnt,h[N],can[N],vis[N][N],A[2][N][N];",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "inline int findmin(Re alpha,Re op);",
            "inline int findmax(Re beta,Re op);",
            "inline int findmin(Re alpha,Re op){",
            "\tif(cnt==n*m)return 0;",
            "\tRe ans=inf;",
            "\tfor(Re i=1,j;i<=n;++i)",
            "\t\tif(h[i]<m&&vis[i][j=h[i]+1]==-1&&h[i-1]>=j){",
            "\t\t\tvis[i][j]=op,++cnt,++h[i];",
            "\t\t\tans=min(ans,-A[op][i][j]+findmax(ans+A[op][i][j],op^1));",
            "\t\t\tvis[i][j]=-1,--cnt,--h[i];",
            "\t\t\tif(ans<=alpha)return ans;",
            "\t\t}",
            "\treturn ans;",
            "}",
            "inline int findmax(Re beta,Re op){",
            "\tif(cnt==n*m)return 0;",
            "\tRe ans=-inf;",
            "\tfor(Re i=1,j;i<=n;++i)",
            "\t\tif(h[i]<m&&vis[i][j=h[i]+1]==-1&&h[i-1]>=j){",
            "\t\t\tvis[i][j]=op,++cnt,++h[i];",
            "\t\t\tans=max(ans,A[op][i][j]+findmin(ans-A[op][i][j],op^1));",
            "\t\t\tvis[i][j]=-1,--cnt,--h[i];",
            "\t\t\tif(ans>=beta)return ans;",
            "\t\t}",
            "\treturn ans;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m);",
            "\tfor(Re i=1;i<=n;++i)",
            "\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\tin(A[1][i][j]);",
            "\tfor(Re i=1;i<=n;++i)",
            "\t\tfor(Re j=1;j<=m;++j)",
            "\t\t\tin(A[0][i][j]);",
            "\tmemset(vis,-1,sizeof(vis));",
            "\th[0]=inf; ",
            "\tprintf(\"%d\\n\",findmax(inf,1));",
            "}",
            ""
        ],
        "description": "插入 对抗搜索+Alpha-Beta  (一双木棋chess TLE)"
    }
}