QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225702#7398. Triangle TilingCrysflyWA 1ms7820kbC++172.5kb2023-10-25 00:34:132023-10-25 00:34:13

Judging History

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

  • [2023-10-25 00:34:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7820kb
  • [2023-10-25 00:34:13]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2") 
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
 
#define maxn 5005
#define inf 0x3f3f3f3f

int n,a[maxn][maxn],b[maxn][maxn];
char s[maxn];

int mx[maxn<<2],tag[maxn<<2];
void build(int p,int l,int r){
	tag[p]=mx[p]=0;
	if(l==r)return;
	int mid=l+r>>1;
	build(p<<1,l,mid),build(p<<1|1,mid+1,r);
}
void add(int p,int l,int r,int nl,int nr,int v){
	if(l>=nl&&r<=nr)return tag[p]+=v,mx[p]+=v,void();
	int mid=l+r>>1;
	if(nl<=mid)add(p<<1,l,mid,nl,nr,v);
	if(nr>mid)add(p<<1|1,mid+1,r,nl,nr,v);
	mx[p]=max(mx[p<<1],mx[p<<1|1])+tag[p];
}

vi vec[maxn];
int p[maxn],len;

bool work()
{
	n=read();
	int cz=0;
	For(i,1,n){
		For(j,1,i){
			char ch;
			while(!isdigit(ch=getchar()));
			a[i][j]=ch&1,b[i][j]=0;
			if(!a[i][j])++cz;
		}
	}
	assert(cz==n);
	For(i,1,n)vec[i].clear();
	For(i,1,n)For(j,1,i)
		if(!a[i][j])vec[i-j+1].pb(j);
	Rep(i,n,1){
	//	cout<<"chk "<<i<<"\n";
		len=0;
		For(j,1,i)
			if(!a[i][j] || b[i][j]==2) p[++len]=j;
	//	cout<<"p: ";For(j,1,len)cout<<p[j]<<" "; cout<<"\n";
		if(i==1)break;
		if(!len) return 0;
		For(j,1,i)
			if(!a[i][j])vec[i-j+1].pop_back();
		For(j,1,p[1]-1) b[i][j]=3;
		For(j,p[len]+1,i) b[i][j]=1;
		build(1,1,i);
		int now=-1,pos=0;
		For(j,1,i){
			if(j==p[1]) now=2,pos=j;
			add(1,1,i,1,i,1);
			for(int x:vec[i-j+1]) add(1,1,i,1,x,-1);
			if(mx[1]<0) return 0;
			if(pos && mx[1]==0)pos=j+1;
			if(pos && now<=len && j+1==p[now]){
				if(mx[1]==0) return 0;
				b[i-1][pos]=2;
				For(x,p[now-1]+1,pos) b[i][x]=1;
				For(x,pos+1,p[now]-1) b[i][x]=3;
				add(1,1,i,1,pos,-1);
				pos=p[now];
				++now;
			}
		}
	}
	For(i,1,n){
		For(j,1,i)putchar("-123"[b[i][j]]);
		puts("");
	}
	return 1;
}

signed main()
{
	int T=read();
	while(T--)if(!work())puts("Impossible!");
    return 0;
}
/*
1
8
1
11
111
1011
11010
011110
1101110
01111111

2
22
222
2-22
23-2-
-3213-
33-333-
-1111111
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7820kb

input:

1
4
0
11
010
1101

output:

-
21
-3-
33-1

result:

ok ok

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5880kb

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!
-
21
221
2-21
2323-
-3233-
33-333-
-1111111
Impossible!
Impossible!
Impossible!
-
-1
332
33--
2
--
2
--
Impossible!
-
21
--1
-
-1
Impossible!
2
22
2--
-3-1
Impossible!
-
21
-3-
2111
-2111
3233-1
3--1111
333...

result:

wrong answer invalid hole in output