QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420100#7398. Triangle TilingBronyaWA 1ms5668kbC++142.0kb2024-05-24 14:39:382024-05-24 14:39:40

Judging History

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

  • [2024-05-24 14:39:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5668kb
  • [2024-05-24 14:39:38]
  • 提交

answer

#include<bits/stdc++.h>
#define lson rt<<1
#define rson rt<<1|1

using namespace std;
int n;
char s[5005];
bool mp[5005][5005];
vector<pair<int,int> >vt;
vector<int>hav[5005];
char ans[5005][5005];
int fa[5005],fr[5005];
void Init(int x){
	fr[0]=0;
    for(int i=1;i<=x;i++)fa[i]=fr[i]=i;
}
int Find(int x){
    return (fa[x]!=x?fa[x]=Find(fa[x]):x);
}
void shaber(){
    puts("Impossible!");
    exit(0);
}
void del(int x){
    int y=Find(x);
    if(y==x)fa[x]=Find(x-1),fr[Find(x-1)]=fr[x];
    else fa[fr[y]+1]=y,fr[y]=fr[fr[y]+1];
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s+1);
        for(int j=1;j<=i;j++){
            mp[i][j]=s[j]-'0';
            if(mp[i][j]==0)vt.push_back({i,j}),ans[i][j]='-';
        }
    }
    for(int i=n;i>=1;i--){
        for(int j=1;j<=i;j++)hav[j].clear();
        for(auto [x,y]:vt){
            if(x>=i)break;
            hav[y+(i-1-x)].push_back(y);
        }
        vector<int>sb;
        for(int j=1;j<=i;j++)
            if(mp[i][j]==0)sb.push_back(j);
        if(sb.empty())shaber();
        for(int j=1;j<sb[0];j++)ans[i][j]='3';
        for(int j=sb[sb.size()-1]+1;j<=i;j++)ans[i][j]='1';
        if(sb.size()==1)continue;
        Init(i+1);
        for(int j=1;j<sb[0];j++){
            for(auto x:hav[j])del(x);
            if(fa[j+1]!=j+1)shaber();
        } 
        for(int j=0;j+1<sb.size();j++){
            int u=sb[j],v=sb[j+1],r=u-1;
            for(int k=u;k<v;k++){
                 for(auto x:hav[k]){
                 	del(x);
                 }
                if(fa[k+1]!=k+1)shaber();
                if(Find(k)+1<=u)r=k;
            }
            if(r==v-1)shaber();
            ans[i-1][r+1]='2';
            mp[i-1][r+1]=0;del(r+1);
            for(int k=u+1;k<v;k++)ans[i][k]=(k<=r+1?'1':'3');
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++)
            putchar(ans[i][j]);
        putchar('\n');
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5668kb

input:

1
4
0
11
010
1101

output:

Impossible!

result:

wrong answer jury has a solution while user does not