QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225721 | #7398. Triangle Tiling | Crysfly | WA | 2ms | 8108kb | C++17 | 3.6kb | 2023-10-25 01:57:31 | 2023-10-25 01:57: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;
}
namespace out{
char buffer[1<<21];int p1=-1;const int p2 = (1<<21)-1;
inline void flush(){fwrite(buffer,1,p1+1,stdout),p1=-1;}
inline void putc(const char &x) {if(p1==p2)flush();buffer[++p1]=x;}
template <typename T>void write(T x) {
static char buf[15];static int len=-1;if(x>=0){do{buf[++len]=x%10+48,x/=10;}while (x);}else{putc('-');do {buf[++len]=-(x%10)+48,x/=10;}while(x);}
while (len>=0)putc(buf[len]),--len;
}
void out(string &s){
for(auto c:s)putc(c);
}
}
#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(int O)
{
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;
}
}
if(0&&O==13){
cout<<n<<"\n";
For(i,1,n){
For(j,1,i)cout<<a[i][j];puts("");
}puts("");exit(0);
}
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;
if(!a[i][1]||b[i][1]==2);
else add(1,1,i,1,1,-1);
For(j,1,i-1){
if(j==p[1]) now=2,pos=j;
if(!a[i][j+1]||b[i][j+1]==2);
else add(1,1,i,1,j+1,-1);
for(int x:vec[i-j]){
add(1,1,i,1,x,1);
}
if(mx[1]>0) return 0;
// cout<<"POS "<<pos<<"\n";
if(pos && now<=len && j+1==p[now]){
if(pos==j+1) 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;
pos=p[now];
++now;
}
if(pos && ask(1,1,i,1,pos+1)==0)pos=j+1;
}
}
For(i,1,n){
For(j,1,i)out::putc("-123"[b[i][j]]);
out::putc('\n');
}
return 1;
}
signed main()
{
// freopen("my.out","w",stdout);
int T=read();
string qwq="Impossible!";
For(_,1,T)if(!work(_))out::out(qwq);
out::flush();
return 0;
}
/*
1
4
1
01
110
1100
1
6
1
11
111
1011
11010
010110
1
8
1
11
111
1011
11010
011110
1101110
01111111
-
-1
332
33--
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 8108kb
input:
1 4 0 11 010 1101
output:
- 21 -3- 33-1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 7888kb
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!Impossible!2 -- 2 -- Impossible!- 21 --1 - -1 Impossible!2 22 2-- -3-1 Impossible!2 -2 -1- 2111 -2111 3233-1 3--1111 3333-111 Impossi...
result:
wrong answer jury does not has a solution while user does