QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#462958 | #6474. Tetris | Random_Code | AC ✓ | 404ms | 142180kb | C++20 | 4.1kb | 2024-07-04 10:27:15 | 2024-07-04 10:27:15 |
Judging History
answer
//ANMHLIJKTJIY!
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define F first
#define S second
#define ll long long
#define map cc_hash_table
#define N 55
#define M 20000010
using namespace std;
using namespace __gnu_pbds;
ll mm[M];
ll st[10][4]={
{272,-1,-1,-1},
{744,711,117,447},
{631,136,463,364},
{326,471,-1,-1},
{623,174,-1,-1},
{227,474,722,171},
{273,276,672,372},
{236,472,362,271},
{376,673,-1,-1},
{176,663,374,633}};
ll cnt=0,deg[M],dis[M];
map<ll,ll> idx[N];//,nxt[N];
vector<ll> vt[M];
ll n,a[N];
ll getfall(ll mask)
{
ll i,j;
vector<ll> vec;
while(mask>=(1ll<<30))
{
vec.push_back((mask>>30)&7);
if(vec.back()==0)
{
vec.pop_back();
}
mask=((mask>>33)<<30)|(mask&((1ll<<30)-1));
}
if(vec.empty())
{
return mask;
}
for(i=9;i>=0;i--)
{
for(j=0;j<vec.size();j++)
{
if((mask>>((i+j)*3))&vec[j])
{
j=-1;
break;
}
}
if(j==-1)
{
break;
}
}
i++;
for(j=0;j<vec.size();j++)
{
mask|=vec[j]<<((i+j)*3);
}
for(i=0;i<10;i++)
{
if(((mask>>(i*3))&7)==7)
{
mask^=7<<(i*3);
vec.clear();
for(j=i+1;j<10;j++)
{
vec.push_back((mask>>(j*3))&7);
mask^=vec.back()<<(j*3);
}
for(j=0;j<vec.size();j++)
{
mask|=vec[j]<<(30+j*3);
}
return mask;
}
}
return mask;
}
ll getnxt(ll mask,ll x,ll y)
{
if(mask>=(1<<21))
{
return -1;
}
if(st[x][y]<0)
{
return -1;
}
// if(nxt[x<<2|y].find(mask)!=nxt[x<<2|y].end())
// {
// return nxt[x<<2|y][mask];
// }
// ll qwq=mask;
ll i,j,v0=st[x][y]%10,v1=(st[x][y]/10)%10,v2=st[x][y]/100;
for(i=9;i>=0;i--)
{
if((mask>>(i*3))&v0)
{
break;
}
if((mask>>(i*3+3))&v1)
{
break;
}
if((mask>>(i*3+6))&v2)
{
break;
}
}
if(i>=7)
{
return -1;
// return nxt[x<<2|y][qwq]=-1;
}
ll ret=0;
mask|=v0<<(i*3+3);
mask|=v1<<(i*3+6);
mask|=v2<<(i*3+9);
for(i=j=0;i<10;i++)
{
if(((mask>>(i*3))&7)>0&&((mask>>(i*3))&7)<7)
{
ret|=((mask>>(i*3))&7)<<(j*3);
j++;
}
}
return ret;
// while(true)
// {
// ll nxt=getfall(mask);
// if(nxt==mask)
// {
// break;
// }
// mask=nxt;
// }
// if(mask>=(1ll<<30))
// {
// mask=-1;
// }
// return nxt[x<<2|y][qwq]=ret;
}
void print(ll mask)
{
ll i,j;
for(i=9;i>=0;i--)
{
for(j=2;j>=0;j--)
{
cout<<((mask>>(i*3+j))&1);
}
puts("");
}
return;
}
ll dfs(ll x,ll y)
{
if(idx[x].find(y)!=idx[x].end())
{
return idx[x][y];
}
ll i,cur;
cur=cnt++;
mm[cur]=y;
idx[x][y]=cur;
for(i=0;i<4;i++)
{
ll v=getnxt(y,a[x],i);
if(v>=0)
{
// print(y);
// cout<<a[x]<<" , "<<i<<endl;
// print(v);
// puts("***********************************");
vt[cur].push_back(dfs((x+1)%n,v));
// cout<<cur<<" -> "<<vt[cur].back()<<endl;
deg[vt[cur].back()]++;
}
}
return cur;
}
//ll lst[M];
//void getpath(ll x)
//{
// if(x==0)
// {
// print(mm[x]);
// puts("--------------------------------------------");
// return;
// }
// getpath(lst[x]);
// print(mm[x]);
// puts("--------------------------------------------");
// return;
//}
int main(){
ll i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
dfs(0,0);
// cout<<cnt<<"!!!!\n";
queue<ll> qu;
for(i=0;i<cnt;i++)
{
if(!deg[i])
{
qu.push(i);
}
}
while(!qu.empty())
{
ll x=qu.front();
qu.pop();
for(i=0;i<vt[x].size();i++)
{
deg[vt[x][i]]--;
if(deg[vt[x][i]]==0)
{
// lst[vt[x][i]]=x;
dis[vt[x][i]]=dis[x]+1;
qu.push(vt[x][i]);
}
}
}
ll ans=0;
for(i=0;i<cnt;i++)
{
if(deg[i])
{
puts("-1");
return 0;
}
ans=max(ans,dis[i]);
}
cout<<ans<<'\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 22ms
memory: 7968kb
input:
1 0
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 27ms
memory: 7964kb
input:
2 3 4
output:
12
result:
ok single line: '12'
Test #3:
score: 0
Accepted
time: 25ms
memory: 7752kb
input:
3 5 1 1
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 23ms
memory: 8452kb
input:
10 5 8 1 5 6 2 9 9 9 9
output:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 29ms
memory: 11464kb
input:
20 5 5 7 9 9 9 9 9 1 2 3 6 9 9 9 9 9 9 9 9
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 41ms
memory: 16120kb
input:
30 5 5 7 1 8 1 3 9 1 8 2 9 9 2 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 24ms
memory: 9280kb
input:
40 9 9 1 9 9 9 1 7 1 1 8 9 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 190ms
memory: 82876kb
input:
50 9 9 1 5 9 5 2 1 6 5 9 9 6 4 8 4 6 9 1 4 5 7 5 8 9 1 1 1 3 4 2 1 8 4 8 1 3 9 1 6 4 9 8 1 6 1 4 4 7 4
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 26ms
memory: 9740kb
input:
50 2 5 9 9 5 7 1 1 7 9 4 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
106
result:
ok single line: '106'
Test #10:
score: 0
Accepted
time: 28ms
memory: 9412kb
input:
37 2 5 9 9 5 7 1 1 7 9 4 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
80
result:
ok single line: '80'
Test #11:
score: 0
Accepted
time: 22ms
memory: 8048kb
input:
1 2
output:
8
result:
ok single line: '8'
Test #12:
score: 0
Accepted
time: 25ms
memory: 12064kb
input:
2 9 5
output:
42
result:
ok single line: '42'
Test #13:
score: 0
Accepted
time: 23ms
memory: 12988kb
input:
3 1 2 9
output:
78
result:
ok single line: '78'
Test #14:
score: 0
Accepted
time: 107ms
memory: 48668kb
input:
16 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9
output:
423
result:
ok single line: '423'
Test #15:
score: 0
Accepted
time: 183ms
memory: 86540kb
input:
30 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
787
result:
ok single line: '787'
Test #16:
score: 0
Accepted
time: 261ms
memory: 119092kb
input:
42 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1099
result:
ok single line: '1099'
Test #17:
score: 0
Accepted
time: 297ms
memory: 127964kb
input:
46 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1203
result:
ok single line: '1203'
Test #18:
score: 0
Accepted
time: 299ms
memory: 138108kb
input:
50 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1307
result:
ok single line: '1307'
Test #19:
score: 0
Accepted
time: 102ms
memory: 47704kb
input:
50 1 2 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1153
result:
ok single line: '1153'
Test #20:
score: 0
Accepted
time: 140ms
memory: 63852kb
input:
50 4 8 1 9 5 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1107
result:
ok single line: '1107'
Test #21:
score: 0
Accepted
time: 314ms
memory: 137288kb
input:
49 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1281
result:
ok single line: '1281'
Test #22:
score: 0
Accepted
time: 136ms
memory: 61056kb
input:
50 9 1 6 9 9 9 9 9 4 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1104
result:
ok single line: '1104'
Test #23:
score: 0
Accepted
time: 293ms
memory: 133524kb
input:
48 9 6 1 3 1 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
output:
1255
result:
ok single line: '1255'
Test #24:
score: 0
Accepted
time: 135ms
memory: 51536kb
input:
15 1 6 1 8 1 8 1 8 1 8 1 8 1 8 1
output:
168
result:
ok single line: '168'
Test #25:
score: 0
Accepted
time: 404ms
memory: 142180kb
input:
47 1 6 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1 8 1
output:
520
result:
ok single line: '520'