QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225701 | #7398. Triangle Tiling | Crysfly | WA | 1ms | 5920kb | C++17 | 2.4kb | 2023-10-25 00:32:12 | 2023-10-25 00:32:12 |
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];
}
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(!len) return 0;
if(i==1)break;
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;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5920kb
input:
1 4 0 11 010 1101
output:
- 21 -3- 33-1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 5820kb
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! Impossible! Impossible! Impossible! Impossible! Impossible! 2 -- 2 -- Impossible! - 21 --1 - -1 Impossible! 2 22 2-- -3-1 Impossible! Impossible! Impossible! Impossible! 2 -- 3-1 2 -- 33- Impossible! Imposs...
result:
wrong answer jury has a solution while user does not