QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340255#7398. Triangle TilingC1942huangjiaxuWA 1ms5864kbC++141.9kb2024-02-28 19:56:432024-02-28 19:56:43

Judging History

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

  • [2024-02-28 19:56:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5864kb
  • [2024-02-28 19:56:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5005;
int n,m,tot;
int ct[N<<2],mx[N<<2],p[N];
char s[N][N],t[N][N];
vector<int>e[N];
void end(){
	puts("Impossible!");
	exit(0);
}
#define L k<<1
#define R k<<1|1
inline void pushup(int k){
	ct[k]=ct[L]+ct[R];
	mx[k]=max(mx[L],mx[R]+ct[L]);
}
void build(int k,int l,int r){
	if(l==r)return mx[k]=ct[k]=1,void();
	int mid=l+r>>1;
	build(L,l,mid),build(R,mid+1,r);
	pushup(k);
}
void modify(int k,int l,int r,int x,int v){
	if(l==r)return ct[k]+=v,mx[k]+=v,void();
	int mid=l+r>>1;
	if(x<=mid)modify(L,l,mid,x,v);
	else modify(R,mid+1,r,x,v);
	pushup(k);
}
int query(int k,int l,int r,int v){
	if(l==r)return l+1;
	int mid=l+r>>1;
	if(mx[L]>=v)return query(L,l,mid,v);
	return query(R,mid+1,r,v-ct[L]);
}
void getp(int i){
	int ln=m-i+1;
	for(auto v:e[i-1]){
		if(v>ln)break;
		modify(1,1,m,v,-1);
		++tot;
	}
	if(tot>ln)end();
	if(tot==ln)p[ln]=1;
	else{
		if(mx[1]<ln-tot)p[ln]=ln+1;
		else p[ln]=query(1,1,m,ln-tot);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i)for(int j=1;j<=i;++j)if(s[i][j]=='0')t[i][j]='-',e[i-j].push_back(j);
	for(int i=n;i>1;--i){
		vector<int>tmp;
		for(int j=1;j<=i;++j)if(s[i][j]=='0')tmp.push_back(j);
		if(tmp.empty())end();
		for(int j=1;j<tmp[0];++j)t[i][j]='3';
		for(int j=tmp.back()+1;j<=i;++j)t[i][j]='1';
		m=i-1,tot=0;
		build(1,1,m);
		for(int j=1;j<tmp[0];++j)getp(i-j);
		for(int j=1;j<tmp.size();++j){
			int l=tmp[j-1],r=tmp[j],u=l;
			for(int k=l;k<r;++k){
				getp(i-k);
				if(p[k]<=l)u=k+1;
			}
			if(u==r)end();
			s[i-1][u]='0',t[i-1][u]='2';
			modify(1,1,m,u,-1);
			++tot;
			for(int k=l+1;k<=u;++k)t[i][k]='1';
			for(int k=u+1;k<r;++k)t[i][k]='3';
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=i;++j)putchar(t[i][j]);
		putchar(10);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5864kb

input:

1
4
0
11
010
1101

output:


result:

wrong output format Unexpected end of file - token expected