QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#856497#9922. Mah-jongzhuge0TL 0ms3584kbC++201.5kb2025-01-14 06:08:462025-01-14 06:08:47

Judging History

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

  • [2025-01-14 06:08:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3584kb
  • [2025-01-14 06:08:46]
  • 提交

answer

#include <bits/stdc++.h>  
#define ll long long  
using namespace std;  
const long long mod = 20020219, inf = 1e18;  
ll n, m, k, q,l,r,cnt=0,ans=0;
map<vector<int>,int> mmp;
ll arr[200005]{};
int num[19]{};
vector<int> pre(9),suf(9),temp(9);
void dfs(int depth)
{
    if(depth==7)
    {
        bool tag=true;
        for(int i=1;i<=8;i++)
        {   
            temp[i]=pre[i]-num[i];
            if(temp[i]<0) tag=false;
            temp[i]%=3;       
        }
        if(tag)
        {//for(int i=1;i<=8;i++) cout<<temp[i]<<' ';
           // cout<<mmp[temp]<<'\n';
         ans+=mmp[temp];
        }
        return ;
    }
    for(int i=0;i<=2;i++)
    {
        num[depth]+=i,num[depth+1]+=i,num[depth+2]+=i;
        dfs(depth+1);
        num[depth]-=i,num[depth+1]-=i,num[depth+2]-=i;
    }
}
void solve() { 
    mmp.clear();
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<9;i++) pre[i]=0,suf[i]=0;
    ans=0;
    mmp[pre]++;
    for(int i=1;i<=n;i++)
    {  // cout<<arr[i]<<'a';
        pre[arr[i]]++;
        suf[arr[i]]=pre[arr[i]]%3;
        // for(int i=1;i<10;i++)
        // {
        //     cout<<suf[i]<<' '; 
        // }
       // cout<<'\n';
        dfs(1); 
        mmp[suf]++;
        //cout<<ans<<' ';
    }
    cout<<ans<<'\n';
}
int main() {  
    ios::sync_with_stdio(false);  
    cin.tie(0);  
    //pre();
    int T = 1;  
    cin >> T; 
    while(T--) {  
        solve();  
    }  
    return 0;  
}
/*

*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

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: