QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#841059#9922. Mah-jongrqoi031TL 60ms190444kbC++201.9kb2025-01-03 11:51:362025-01-03 11:51:37

Judging History

This is the latest submission verdict.

  • [2025-01-03 11:51:37]
  • Judged
  • Verdict: TL
  • Time: 60ms
  • Memory: 190444kb
  • [2025-01-03 11:51:36]
  • Submitted

answer

#include<stdio.h>
#include<algorithm>
typedef long long ll;
constexpr int N{100000},L{8},C{729};
int cnt[C+5][L];
void init() {
    int tot{0};
    for(int i=0;i!=1<<(L-2<<1);i++) {
        if([&]()->bool {
            for(int j=0;j!=L-2;j++) {
                if((i>>(j<<1)&3)>=3) {
                    return true;
                }
            }
            return false;
        }()) {
            continue;
        }
        ++tot;
        std::fill(cnt[tot],cnt[tot]+L,0);
        for(int j=0;j!=L-2;j++) {
            int c{i>>(j<<1)&3};
            cnt[tot][j]+=c;
            cnt[tot][j+1]+=c;
            cnt[tot][j+2]+=c;
        }
    }
}
int a[N+5],c[N+5][L],v[N+5];
int ptr[C+5],ccc[C+5][(1<<(L<<1))+5];
void solve() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",a+i),--a[i];
    }
    ll ans{0};
    std::fill(c[0],c[0]+L,0);
    for(int i=1;i<=C;i++) {
        std::fill(ccc[i],ccc[i]+(1<<(L<<1)),0);
    }
    std::fill(ptr+1,ptr+C+1,0);
    for(int i=1;i<=n;i++) {
        std::copy(c[i-1],c[i-1]+L,c[i]);
        ++c[i][a[i]];
        v[i]=0;
        for(int j=0;j!=L;j++) {
            v[i]|=c[i][j]%3<<(j<<1);
        }
        for(int j=1;j<=C;j++) {
            while(ptr[j]<i&&[&]()->bool {
                for(int p=0;p!=L;p++) {
                    if(c[i][p]-c[ptr[j]][p]<cnt[j][p]) {
                        return false;
                    }
                }
                return true;
            }()) {
                ++ccc[j][v[ptr[j]++]];
            }
            int val{0};
            for(int p=0;p!=L;p++) {
                val|=(c[i][p]-cnt[j][p]+3)%3<<(p<<1);
            }
            ans+=ccc[j][val];
        }
    }
    printf("%lld\n",ans);
}
int main() {
    init();
    int t;
    scanf("%d",&t);
    while(t--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 60ms
memory: 190444kb

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
Time Limit Exceeded

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:


result: