QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#841525#9922. Mah-jonggrass8cowTL 1922ms33496kbC++172.1kb2025-01-03 19:52:192025-01-03 19:52:20

Judging History

你现在查看的是最新测评结果

  • [2025-01-03 19:52:20]
  • 评测
  • 测评结果:TL
  • 用时:1922ms
  • 内存:33496kb
  • [2025-01-03 19:52:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int e[10],o[12],pp;
vector<int>kc[1010010];
void dfs(int x){
    if(x==9){
        int z=0;
        for(int i=1;i<=8;i++)z+=e[i],o[i]=e[i];
        o[9]=o[10]=0;
        if(z%3)return;
        bool gg=0;
        for(int i=1;i<=10;i++){
            if(o[i]<0){gg=1;break;}
            if(o[i]>=3)o[i]-=3;if(o[i]>=3)o[i]-=3;
            if(o[i])o[i+2]-=o[i],o[i+1]-=o[i];
        }
        if(!gg){
            int jb=0,xx=0;
            for(int i=1;i<=8;i++)
                jb=jb*5+min(e[i],4),xx=xx*4+(e[i]%3);
            kc[jb].push_back(xx);
        }
        return;
    }
    for(int i=0;i<=6;i++)e[x]=i,dfs(x+1);
}
int n,a[101000],P5[10],tp[10],xp[100100];
vector<int>g[100100];
long long ans;
int p[38],hs,nt[10];
void sol(){
    memset(tp,0,sizeof(tp));
    scanf("%d",&n);
    hs=0;
    ans=0;
    xp[0]=0,g[0].push_back(0);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        tp[a[i]]++;if(tp[a[i]]>=3)tp[a[i]]%=3;
        int xx=0;
        for(int j=1;j<=8;j++)xx=xx*3+tp[j];
        g[xx].push_back(i),xp[i]=xx;
        int kn=0,PP=0;
        for(int j=hs;j;j--)if(a[i]==a[p[j]])PP=j,kn++;
        if(kn<4)p[++hs]=i;
        else{
            for(int j=PP;j<hs;j++)p[j]=p[j+1];
            p[hs]=i;
        }
        memset(nt,0,sizeof(nt));int st=0;
        for(int j=hs;j;j--){
            int o=a[p[j]];
            if(nt[o]<4)st+=P5[8-o];
            nt[o]++;
            for(int m_:kc[st]){
                int mm=0;
                for(int i=1;i<=8;i++){
                    int e=3-((m_>>(16-i*2))&3)+tp[i];
                    if(e>=3)e-=3;
                    mm=mm*3+e;
                }
                int l=lower_bound(g[mm].begin(),g[mm].end(),p[j-1])-g[mm].begin();
                int r=lower_bound(g[mm].begin(),g[mm].end(),p[j])-g[mm].begin();
                ans+=r-l;
            }
        }
    }
    for(int i=0;i<=n;i++)g[xp[i]].clear();
    printf("%lld\n",ans);
}
int main(){
    P5[0]=1;
    for(int i=1;i<=8;i++)P5[i]=P5[i-1]*5;
    dfs(1);
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 100ms
memory: 33484kb

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: 0
Accepted
time: 1922ms
memory: 33496kb

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:

51699
61486
5146
1960
241675
6274
11224
46170
435241
1219228
17198
139542
299436
960439
217729
1174
87401
141087
69813
1
78895
0
39510
16757
86551
0
100302
161956
3
512157
58619
196941
26116
61635
28879
11511
2061
4394
74620
907389
172780
23952
524
87857
1305332
1413
11784
156368
11746
23217
25189
9...

result:

ok 100 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

1
100000
7 6 3 7 1 2 5 2 4 5 3 2 6 2 2 2 5 6 5 8 6 2 1 8 2 2 1 1 4 8 2 6 4 1 8 6 6 7 8 4 4 5 4 7 8 6 2 3 3 7 5 7 1 1 3 5 2 8 5 6 3 6 2 3 3 8 4 5 7 8 1 5 6 1 3 4 5 7 1 5 4 4 4 6 6 4 2 3 5 2 7 3 5 8 7 1 5 4 5 4 1 5 8 7 2 2 8 2 4 3 5 7 6 6 1 6 6 3 1 1 3 1 7 8 1 7 3 7 8 3 6 3 5 7 5 1 8 7 4 7 5 4 8 1 3 4...

output:


result: