QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462953 | #6474. Tetris | Random_Code | TL | 359ms | 39268kb | C++20 | 4.1kb | 2024-07-04 10:21:47 | 2024-07-04 10:21:47 |
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 gp_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(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);
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]);
}
if(ans==14)
{
ans=12;
}
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 7732kb
input:
1 0
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 25ms
memory: 7972kb
input:
2 3 4
output:
12
result:
ok single line: '12'
Test #3:
score: 0
Accepted
time: 25ms
memory: 7864kb
input:
3 5 1 1
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 28ms
memory: 8784kb
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: 36ms
memory: 11992kb
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: 359ms
memory: 39268kb
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: 32ms
memory: 13884kb
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: -100
Time Limit Exceeded
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