QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#858633 | #9922. Mah-jong | the_same_prayers# | WA | 2ms | 10032kb | C++14 | 2.7kb | 2025-01-16 19:54:11 | 2025-01-16 19:54:11 |
Judging History
answer
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
long long t,n,m,k,flag[N],ans=1,mod=998244353,a[N],cnt,nown,pre[N][10],nub[10],xx[10];
inline long long rd()
{
long long x = 0, f = 1;
char ch = getchar();
while(ch<'0'||ch>'9')
{
if(ch == '-') f=-1;
ch = getchar();
}
while(ch>='0'&&ch<='9')
{
x = ( x << 1 ) + ( x << 3 ) + ( ch ^ 48 );
ch = getchar();
}
return x * f;
}
long long det()
{
xx[1]=nub[1]%3;
if(nub[2]<xx[1]){return 0;}
xx[2]=(nub[2]-xx[1])%3;
for(int j=3;j<=6;j++)
{
if(nub[j]-xx[j-2]-xx[j-1]<0)return 0;
xx[j]=(nub[j]-xx[j-2]-xx[j-1])%3;
}
if((nub[7]-xx[5]-xx[6])%3==0&&(nub[8]-xx[6])%3==0)return 1;
else return 0;
}
int main()
{
// cin>>n;
// for(int j=1;j<=n;j++)
// nub[j]=rd();
// cout<<det()<<endl;
cin>>t;
for(int i=1;i<=t;i++)
{
n=rd();ans=0;
for(int j=1;j<=n+1;j++)
{
flag[j]=-1;
}
for(int j=1;j<=n;j++)
{
long long c=rd();
for(int l=1;l<=8;l++)
pre[j][l]=pre[j-1][l];
pre[j][c]++;
}
for(int j=1;j<=n-2;j++)
{
for(int l=1;l<=8;l++)
{
nub[l]=pre[j+2][l]-pre[j-1][l];
}
if(det())flag[j]=j+2;
else flag[j]=-1;
}
for(int l=1;l<=8;l++)nub[l]=0;
nown=n;
for(int j=n-2;j>=1;j-=3)
{
if(flag[j]!=-1)continue;
for(int l=1;l<=8;l++)
{
nub[l]+=pre[j+2][l]-pre[j-1][l];
}
if(det())
{
flag[j]=nown;nown=j-1;
for(int l=1;l<=8;l++)nub[l]=0;
}
}
for(int l=1;l<=8;l++)nub[l]=0;
nown=n-1;
for(int j=n-3;j>=1;j-=3)
{
if(flag[j]!=-1)continue;
for(int l=1;l<=8;l++)
{
nub[l]+=pre[j+2][l]-pre[j-1][l];
}
if(det())
{
flag[j]=nown;nown=j-1;
for(int l=1;l<=8;l++)nub[l]=0;
}
}
for(int l=1;l<=8;l++)nub[l]=0;
nown=n-2;
for(int j=n-4;j>=1;j-=3)
{
if(flag[j]!=-1)continue;
for(int l=1;l<=8;l++)
{
nub[l]+=pre[j+2][l]-pre[j-1][l];
}
if(det())
{
flag[j]=nown;nown=j-1;
for(int l=1;l<=8;l++)nub[l]=0;
}
}
// long long bg=0;
cnt=0;
for(int j=1;j<=n+1;)
{
if(flag[j]==-1)
{
ans+=cnt*(cnt+1)/2;
cnt=0;j+=3;
}
else
{
cnt++;
j=flag[j]+1;
}
}
cnt=0;
for(int j=2;j<=n+1;)
{
if(flag[j]==-1)
{
ans+=cnt*(cnt+1)/2;
cnt=0;j+=3;
}
else
{
cnt++;
j=flag[j]+1;
}
}
cnt=0;
for(int j=3;j<=n+1;)
{
if(flag[j]==-1)
{
ans+=cnt*(cnt+1)/2;
cnt=0;j+=3;
}
else
{
cnt++;
j=flag[j]+1;
}
}
// for(int j=1;j<=n-2;j++)
// {
// cout<<flag[j]<<" ";
// }
// cout<<endl;
cout<<ans<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7716kb
input:
5 4 1 1 1 1 6 1 2 3 1 2 3 7 6 5 8 7 6 3 2 8 1 2 1 2 1 2 1 3 9 2 2 4 4 1 1 1 3 3
output:
2 5 1 3 2
result:
ok 5 number(s): "2 5 1 3 2"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 10032kb
input:
100 992 8 1 8 1 2 3 6 6 1 3 1 8 7 7 4 7 7 1 6 6 4 8 3 7 3 5 1 4 4 7 5 7 5 7 4 3 7 5 2 8 7 1 6 3 6 2 4 3 2 3 1 6 3 1 3 2 6 6 7 4 6 1 1 4 6 4 7 7 8 5 6 4 1 5 4 8 2 4 4 2 1 3 5 7 6 8 3 7 6 6 5 6 4 2 5 4 3 7 3 5 5 3 3 2 7 8 2 7 2 4 4 3 4 1 1 3 5 5 4 6 3 3 3 2 6 1 2 6 4 8 8 6 6 8 7 3 1 1 8 8 7 2 5 6 3 5 ...
output:
1263 1492 117 79 6373 251 368 1226 9592 28386 409 3911 7819 22291 4800 38 1980 3247 1772 1 1936 0 862 447 2153 0 2549 4137 2 12477 1249 4463 594 1520 616 274 93 145 1965 24038 3593 538 21 1830 28914 56 290 4196 373 549 674 316 7262 13 33 464 3040 764 215 12301 695 1139 11 3 177 17 70 2271 3 577 5 16...
result:
wrong answer 1st numbers differ - expected: '51699', found: '1263'