QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#341163#7398. Triangle TilingSkyjoyWA 3ms8256kbC++142.4kb2024-02-29 16:15:332024-02-29 16:15:37

Judging History

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

  • [2024-02-29 16:15:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:8256kb
  • [2024-02-29 16:15:33]
  • 提交

answer

#include<bits/stdc++.h>
#define I using
#define love namespace
#define Elaina std
I love Elaina;
const int N=5010;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int T,n,a[N][N],ans[N][N];
vector<int>pos[N],vec[N];
namespace AyaseEli{
	#define ls(k) (k<<1)
	#define rs(k) (k<<1|1)
	struct node{int l,r,maxn,tag;}tree[N<<2];
	void pushup(node *tree,int k){tree[k].maxn=max(tree[ls(k)].maxn,tree[rs(k)].maxn)+tree[k].tag;}
	void build(node *tree,int k,int l,int r){
		tree[k].l=l,tree[k].r=r,tree[k].tag=0;
		if(l==r){
			tree[k].maxn=l-1;
			return;
		}
		int mid=(l+r)/2;
		build(tree,ls(k),l,mid),build(tree,rs(k),mid+1,r);
		pushup(tree,k);
	}
	void change(node *tree,int k,int qr){
		if(tree[k].r<=qr){
			tree[k].maxn++,tree[k].tag++;
			return;
		}
		int mid=(tree[k].l+tree[k].r)/2;
		change(tree,ls(k),qr);
		if(mid<qr)change(tree,rs(k),qr);
		pushup(tree,k);
	}
	int query(node *tree,int k,int qr){
		if(tree[k].r<=qr)return tree[k].maxn;
		int mid=(tree[k].l+tree[k].r)/2,res=query(tree,ls(k),qr);
		if(mid<qr)res=max(res,query(tree,rs(k),qr));
		return res+tree[k].tag;
	}
}
I love AyaseEli;
void solve(){
	n=read();
	for(int i=1;i<=n;i++){
		pos[i].clear();
		for(int j=1;j<=i;j++){
			scanf("%1d",&a[i][j]);
			if(!a[i][j])ans[i][j]=0;
			else ans[i][j]=-1;
		}
	}
	for(int i=n+1;i>1;i--){
		build(tree,1,1,n);
		pos[i].clear();
		if(i<=n)for(int j=1;j<=i;j++)if(!a[i][j])pos[i].push_back(j);
		if(pos[i].empty()&&i<=n){
			puts("Impossible!");
			return;
		}
		for(int j=1;j<i;j++)vec[j].clear();
		for(int j=1;j<i;j++)for(int tmp:pos[j])vec[i-1-j+tmp].push_back(tmp);
		for(int j=1,l=0,r=0;j<=i;j++){
			for(int tmp:vec[j])change(tree,1,tmp);
			if(!a[i][j]&&i<=n){
				a[i-1][r]=0,ans[i-1][r]=2;
				for(int k=l+1;k<=r;k++)ans[i][k]=1;
				for(int k=r+1;k<j;k++)ans[i][k]=3;
				if(r)change(tree,1,r);
				l=r=j;
			}
			if(i==j){
				for(int k=l+1;k<=i;k++)ans[i][k]=1;
				break;
			}
			if(query(tree,1,j)>j){
				puts("Impossible!");
				return;
			}
			if(l&&query(tree,1,l)>=j)r=j+1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			if(ans[i][j])printf("%d",ans[i][j]);
			else putchar('-');
		}
		puts("");
	}
}
int main(){
	T=read();
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7996kb

input:

1
4
0
11
010
1101

output:

-
21
-3-
33-1

result:

ok ok

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 8256kb

input:

909
6
0
11
100
1111
11100
111110
7
0
11
011
1001
10111
100111
1111111
6
0
00
001
1111
11101
111111
8
1
01
111
1111
10111
101110
1101101
11111100
2
1
00
2
0
01
3
0
01
110
7
1
00
011
1010
11011
110111
1111111
8
1
11
111
1011
11010
011110
1101110
01111111
5
1
00
010
1111
10111
6
0
10
011
0101
01111
111...

output:

-
32
3--
3332
333--
33333-
Impossible!
Impossible!
Impossible!
2
--
-
-1
-
-1
33-
Impossible!
-1
21
221
2-21
2323-
-3233-
33-333-
-1111111
Impossible!
Impossible!
Impossible!
-1
-1
332
33--
2
--
2
--
Impossible!
-
21
--1
-
-1
Impossible!
2
22
2--
-3-1
Impossible!
-1
21
-3-
2111
-2111
3233-1
3--1111
...

result:

wrong answer invalid hole in output