QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#856859#9922. Mah-jongzhuge0WA 857ms5712kbC++201.8kb2025-01-14 18:08:042025-01-14 18:08:04

Judging History

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

  • [2025-01-14 18:08:04]
  • 评测
  • 测评结果:WA
  • 用时:857ms
  • 内存:5712kb
  • [2025-01-14 18:08:04]
  • 提交

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,ans=0,all=0;
int mmp[500005]{};
ll arr[200005]{};
int num[19]{},pw[10]{};
vector<int> pre(9),suf(9),temp(9);
void work()
{
    pw[0]=1;
    for(int i=1;i<=9;i++)
    {
        pw[i]=pw[i-1]*3;
    }
}
void dfs(int depth,int st)
{
    if(depth==7)
    {
       // cout<<st<<' '<<mmp[st]<<'\n';
         ans+=mmp[st];
        return ;
    }
    //cout<<st;
    //cout<<depth<<' ';
    for(int i=0;i<=min({2,pre[depth],pre[depth+1],pre[depth+2]});i++)
    {
        int nst=st;
        if(i)
        {
            if(pre[depth]%3>=i) nst-=i*pw[depth];
            else nst+=(3-i)*pw[depth];
            if(pre[depth+1]%3>=i) nst-=i*pw[depth+1];
            else nst+=(3-i)*pw[depth+1];
            if(pre[depth+2]%3>=i) nst-=i*pw[depth+2];
            else nst+=(3-i)*pw[depth+2];
        }
        //cout<<nst<<'\n';
        pre[depth]-=i,pre[depth+1]-=i,pre[depth+2]-=i;
        dfs(depth+1,nst);
        pre[depth]+=i,pre[depth+1]+=i,pre[depth+2]+=i;
    }
}
void solve() { 
    for(int i=0;i<=50000;i++) mmp[i]=0;
    cin>>n;
    all=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<9;i++) pre[i]=0;
    ans=0;
    mmp[0]++;
    int state=0;
    for(int i=1;i<=n;i++)
    {  // cout<<arr[i]<<'a';
        pre[arr[i]]++;
        if(pre[arr[i]]%3==0) state-=2*pw[arr[i]];
        else state+=pw[arr[i]];
        all=state;
        dfs(1,all); 
        mmp[state]++;
    }
    cout<<ans<<'\n';
}
int main() {  
    //ios::sync_with_stdio(false);  
    //cin.tie(0);  
    work();
    int T = 1;  
    cin >> T; 
    while(T--) {  
        solve();  
    }  
    return 0;  
}
/*

*/

详细

Test #1:

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

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: 857ms
memory: 5708kb

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:

54611
65045
5863
2450
248073
7119
12431
48687
443481
1233932
19142
143983
306768
973691
223671
1693
91315
145847
73072
1
82628
0
42058
18421
90267
0
104563
167091
3
521177
61750
202416
28257
64928
31123
12820
2493
5247
78104
919402
178810
26044
870
91985
1320319
1840
13119
161273
12933
25118
27138
1...

result:

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