QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#462948 | #6474. Tetris | Random_Code | WA | 36ms | 9988kb | C++20 | 4.0kb | 2024-07-04 10:14:23 | 2024-07-04 10:14:25 |
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 nxt[x<<2|y][qwq]=-1;
}
mask|=v0<<(i*3+3);
mask|=v1<<(i*3+6);
mask|=v2<<(i*3+9);
for(i=0;i<10;i++)
{
if(((mask>>(i*3))&7)==7)
{
mask^=7<<(i*3);
}
}
ll ret=0;
for(i=j=0;i<10;i++)
{
if((mask>>(i*3))&7)
{
ret|=((mask>>(i*3))&7)<<(j*3);
j++;
}
}
// 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)
{
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("***********************************");
if(idx[(x+1)%n].find(v)==idx[(x+1)%n].end())
{
vt[cur].push_back(dfs((x+1)%n,v));
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: 31ms
memory: 9672kb
input:
1 0
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 27ms
memory: 9988kb
input:
2 3 4
output:
12
result:
ok single line: '12'
Test #3:
score: -100
Wrong Answer
time: 36ms
memory: 9988kb
input:
3 5 1 1
output:
9
result:
wrong answer 1st lines differ - expected: '-1', found: '9'