QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340125#7398. Triangle Tilingby_chanceWA 0ms28296kbC++142.3kb2024-02-28 15:33:392024-02-28 15:33:40

Judging History

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

  • [2024-02-28 15:33:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:28296kb
  • [2024-02-28 15:33:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5005;
#define ed {printf("Impossible!\n");return 0;}
int n,d[N];char mp[N][N],ans[N][N];
vector<int> pos[N];
#define ls p<<1
#define rs p<<1|1
#define mid ((l+r)>>1)
int add[N<<2],mn[N<<2];
void make_tag(int p,int v){add[p]+=v;mn[p]+=v;}
void push_down(int p){
    int v=add[p];if(!v)return;add[p]=0;
    make_tag(ls,v);make_tag(rs,v);
}
void push_up(int p){mn[p]=min(mn[ls],mn[rs]);}
void build(int p,int l,int r){
    add[p]=mn[p]=0;if(l==r)return;
    build(ls,l,mid);build(rs,mid+1,r);
}
void modify(int p,int l,int r,int R,int v){
    if(r<=R)return make_tag(p,v);push_down(p);
    modify(ls,l,mid,R,v);
    if(R>mid)modify(rs,mid+1,r,R,v);
    push_up(p);
}
int query(int p,int l,int r,int x){
    if(l>=x||mn[p])return -1;
    if(l==r)return l;push_down(p);
    int res=query(ls,l,mid,x);
    return res!=-1?res:query(rs,mid+1,r,x);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",mp[i]+1);
        for(int j=1;j<=i;j++)
            if(mp[i][j]=='0')pos[i-j].push_back(j);
    }
    memset(ans,'-',sizeof(ans));
    for(int i=n;i>1;i--){
        build(1,1,i);int l,r;
        auto ins=[&](int j){
            modify(1,1,i,j,1);
            for(auto x:pos[i-j-1]){
                if(x>j)break;
                modify(1,1,i,x,-1);
            }
            return mn[1]>=0;
        };
        for(l=1;l<=i&&mp[i][l]!='0';l++){
            ans[i][l]='3';if(!ins(l))ed;
        }
        if(l>i)ed;
        while(1){
            for(r=l+1;r<=i&&mp[i][r]=='1';r++);
            if(r>i){for(int j=l+1;j<=i;j++)ans[i][j]='1';break;}
            for(int j=l;j<r;j++){
                if(!ins(j))ed;
                int v=j+1,u=query(1,1,i,v);
                if(u!=-1)u=max(u,l),++d[u],--d[v];
            }
            for(int j=l;j<r;j++)d[j+1]+=d[j];int p=-1;
            for(int j=r-1;j>=l;j--)if(!d[j])p=j;else d[j]=0;
            if(p==-1)ed;
            for(int j=l+1;j<=p;j++)ans[i][j]='1';
            for(int j=p+1;j<r;j++)ans[i][j]='3';
            mp[i-1][p]='0';ans[i-1][p]='2';
            modify(1,1,i,p,-1);if(mn[1]<0)ed;l=r;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++)putchar(ans[i][j]);
        putchar('\n');
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 28296kb

input:

1
4
0
11
010
1101

output:

-

result:

wrong output format Unexpected end of file - token expected