QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858688#9922. Mah-jongthe_same_prayersWA 4ms10024kbC++143.2kb2025-01-16 20:37:002025-01-16 20:37:01

Judging History

This is the latest submission verdict.

  • [2025-01-16 20:37:01]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 10024kb
  • [2025-01-16 20:37:00]
  • Submitted

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],f[N];
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;f[j]=0;
		}
		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;
			}
		}
		for(int j=1;j<=n-2;j++)
		{
			if(f[j])continue;
			else
			{
				long long nn=j;cnt=0;
				
				while(nn<=n+1)
				{
					f[nn]=1;
					if(flag[nn]==-1)
					{
						ans+=cnt*(cnt+1)/2;
//						cnt=0;
						break;
					}
					else
					{
						cnt++;
						nn=flag[nn]+1;
					}
//					cout<<nn<<" ";
				}
//				cout<<endl;
			}
		}
//		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;
////				cout<<j<<" ";
//			}
//		}
//		cnt=0;
////		cout<<endl;
//		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;
////				cout<<j<<" ";
//			}
//		}
////		cout<<endl;
//		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;
////				cout<<j<<" ";
//			}
//		}
//		cout<<endl;
//		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: 7764kb

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: 4ms
memory: 10024kb

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:

2575
3016
142
98
19525
283
514
1881
35271
186620
629
10646
23415
80967
14388
56
4466
7835
3862
1
3308
0
1851
496
4168
0
6277
12852
2
38843
2619
12082
1196
3786
978
396
123
221
4835
92017
10451
741
24
3595
110679
83
795
9699
674
1130
937
535
21220
16
40
1048
7433
1874
384
26800
962
1788
16
3
339
25
1...

result:

wrong answer 1st numbers differ - expected: '51699', found: '2575'