QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225708 | #7398. Triangle Tiling | Crysfly | WA | 1ms | 5864kb | C++17 | 3.0kb | 2023-10-25 01:20:33 | 2023-10-25 01:20:33 |
Judging History
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];
}
int ask(int p,int l,int r,int ql,int qr){
if(l>=ql&&r<=qr)return mx[p];
int mid=l+r>>1,res=-inf;
if(ql<=mid)res=max(res,ask(p<<1,l,mid,ql,qr));
if(qr>mid)res=max(res,ask(p<<1|1,mid+1,r,ql,qr));
return res+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,2){
// 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(!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-1){
// cout<<"j: "<<j<<"\n";
if(j==p[1]) now=2,pos=j;
add(1,1,i,1,i,-1);
for(int x:vec[i-j])
// cout<<"add "<<x<<" "<<j<<"\n",
add(1,1,i,1,x,1);
// cout<<"max "<<mx[1]<<"\n";
// For(x,1,j) cout<<ask(1,1,i,1,x)<<" "; cout<<"\n";
if(mx[1]>0) return 0;
if(pos && ask(1,1,i,1,pos)==0)pos=j+1;
if(pos && now<=len && j+1==p[now]){
if(pos==j+1) return 0;
// cout<<"up "<<pos<<"\n";
// cout<<"range "<<p[now-1]<<" "<<p[now]<<"\n";
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()
{
// freopen("my.out","w",stdout);
int T=read();
while(T--)if(!work())puts("Impossible!");
return 0;
}
/*
1
6
1
11
111
1011
11010
010110
1
8
1
11
111
1011
11010
011110
1101110
01111111
-
-1
332
33--
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5788kb
input:
1 4 0 11 010 1101
output:
- 21 -3- 33-1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5864kb
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! 2 22 222 2-22 23-2- -3213- 33-333- -1111111 Impossible! Impossible! Impossible! - -1 332 33-- 2 -- 2 -- - 21 -21 -132 333-- - 21 --1 - -1 Impossible! 2 22 2-- -3-1 Impossible! 2 -2 -1- 2111 -2111 3233-1 3--...
result:
wrong answer jury does not has a solution while user does