Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
38067 LYLAKIOI 【BJ】T3 C++ 通过 100 387 MS 38724 KB 1650 2025-06-12 15:33:40

Tests(20/20):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define m_p make_pair #define p_b push_back #define pi pair<int,int> #define p1 first #define p2 second using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n; string s1[2005],s2[2005]; int L[4005],R[4005]; inline void chkmin(int &x,int y){if(x>y)x=y;} inline void chkmax(int &x,int y){if(x<y)x=y;} int f[4005],g[4005]; int t[2005][2005]; int ans[2005]; bool vis[2005]; int I; void dfs(int x,int y){ if((!x)&&(!y))return; auto dp=[](int x,int y){ if(x<0||y<0)return 0; if(x<f[x+y]||x>g[x+y])return 0; return 1; }; if(s2[I][x+y-1]!='0'||dp(x,y-1))dfs(x,y-1); else t[I][x]=x+y,dfs(x-1,y); } void slv(){ n=read(); up(i,0,n)cin>>s1[i]; up(i,1,n)cin>>s2[i]; memset(L,0x3f,sizeof(L)); up(i,0,n)up(j,0,n)if(s1[i][j]=='1') chkmin(L[i+j],i),chkmax(R[i+j],i); up(i,1,n){ up(j,1,2*n){ f[j]=f[j-1],g[j]=g[j-1]; if(s2[i][j-1]=='0')g[j]++; chkmax(f[j],L[j]),chkmin(g[j],R[j]); } I=i;dfs(n,n); } up(i,1,n){ int p=0; up(j,1,n)if((!vis[j])&&((!p)||t[j][i]<t[p][i]))p=j; ans[p]=t[p][i],vis[p]=1; } up(i,1,n)printf("%d ",ans[i]); } int main(){ //freopen("bus.in","r",stdin),freopen("bus.out","w",stdout); slv(); return 0; }


测评信息: