QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205178 | #7398. Triangle Tiling | aurelion_sol | WA | 2ms | 5936kb | C++14 | 3.2kb | 2023-10-07 15:05:48 | 2023-10-07 15:05:49 |
Judging History
answer
#include<bits/stdc++.h>
#define rp(i,a,b) for(int i=a;i<=b;++i)
#define pr(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define ls (x<<1)
#define rs (ls|1)
#define md ((l+r)>>1)
using namespace std;
const int N=5e3+5,M=1<<14|5;
char s[N];
int T,n,a[N][N],b[N][N],mx[M],tag[M],posn,pos[N];
vector<int> lft[N];
inline void pushup(int x){
mx[x]=max(mx[ls],mx[rs]);
}
inline void addtag(int x,int y){
mx[x]+=y;
tag[x]+=y;
}
inline void pushdown(int x){
addtag(ls,tag[x]),addtag(rs,tag[x]),tag[x]=0;
}
void build(int x,int l,int r){
mx[x]=r-1;
tag[x]=0;
if(l!=r){
build(ls,l,md),build(rs,md+1,r);
}
}
void modify(int x,int l,int r,int lx,int rx){
if(l>=lx&&r<=rx){
addtag(x,1);
return;
}
pushdown(x);
if(lx<=md)modify(ls,l,md,lx,rx);
if(rx>md)modify(rs,md+1,r,lx,rx);
pushup(x);
}
int query(int x,int l,int r,int lx,int rx){
if(l>=lx&&r<=rx){
return mx[x];
}
pushdown(x);
int ret=0;
if(lx<=md)ret=max(ret,query(ls,l,md,lx,rx));
if(rx>md)ret=max(ret,query(rs,md+1,r,lx,rx));
return ret;
}
void mian(){
scanf("%d",&n);
int zero=0;
rp(i,1,n){
scanf("%s",s+1);
rp(j,1,i){
a[i][j]=s[j]&1;
b[i][j]=0;
if(!a[i][j]){
++zero;
}
}
}
if(zero!=n){
puts("Impossible!");
return;
}
rp(i,1,n){
lft[i].clear();
}
rp(i,1,n){
rp(j,i,n){
if(!a[j][j+1-i]){
lft[i].pb(j+1-i);
}
}
}
build(1,1,n);
rp(i,1,n){
for(int l:lft[n+1-i]){
// printf("[%d %d]\n",l,i);
modify(1,1,n,1,l);
}
if(query(1,1,n,1,i)>i){
puts("Impossible!");
return;
}
}
// puts("ok");
pr(i,n,1){
if(i!=n){
posn=0;
rp(j,1,i+1)if(!a[i+1][j]||b[i+1][j]==2){
pos[++posn]=j;
}
if(!posn){
puts("Impossible!");
return;
}
// printf("row=%d\n",i);
// rp(j,1,posn){
// printf("%d:%d\n",j,pos[j]);
// }
rp(j,1,pos[1]-1){
b[i+1][j]=3;
}
rp(j,pos[posn]+1,i+1){
b[i+1][j]=1;
}
build(1,1,i);
int posp=0,low=0;
// printf("solve(%d)\n",i);
rp(j,1,i){
if(j==pos[1]){
posp=2;
low=pos[1];
}
for(int l:lft[i+1-j]){
// printf("[%d %d]\n",l,j);
modify(1,1,i,1,l);
}
if(query(1,1,i,1,j)>j){
puts("Impossible!");
return;
}
if(low&&query(1,1,i,1,low)==j){
low=j+1;
}
// printf("low=%d\n",low);
if(posp<=posn&&j+1==pos[posp]){
if(low==j+1){
puts("Impossible!");
return;
}
// puts("before...");
// rp(ii,1,n)rp(jj,1,ii){
// printf("%d",b[ii][jj]);
// if(jj==ii)puts("");
// }
rp(k,pos[posp-1]+1,low){
b[i+1][k]=1;
}
b[i][low]=2;
rp(k,low+1,pos[posp]-1){
b[i+1][k]=3;
}
// printf("omg low=%d\n",low);
// rp(ii,1,n)rp(jj,1,ii){
// printf("%d",b[ii][jj]);
// if(jj==ii)puts("");
// }
// _sleep(2000);
modify(1,1,i,1,low);
++posp;
}
}
}
rp(j,1,i)if(!a[i][i+1-j]){
lft[j].pop_back();
}
}
rp(i,1,n){
rp(j,1,i)putchar("-123"[b[i][j]]);
puts("");
}
}
int main(){
//freopen("1.in","r",stdin);
scanf("%d",&T);
while(T--){
mian();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5936kb
input:
1 4 0 11 010 1101
output:
- 21 -3- 33-1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 5884kb
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! - 21 23- -3-1 Impossible! 2 -2 -1- 2111 -2111 3233-1 3--1111 3333-111 Impossible! Impossible! 2 --...
result:
wrong answer jury has a solution while user does not