QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836656#9922. Mah-jongucup-team1134#TL 2ms3672kbC++232.6kb2024-12-29 03:21:372024-12-29 03:21:37

Judging History

This is the latest submission verdict.

  • [2024-12-29 03:21:37]
  • Judged
  • Verdict: TL
  • Time: 2ms
  • Memory: 3672kb
  • [2024-12-29 03:21:37]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

vvi chi;
vi S(8);

void DFS(int u){
    if(u==6){
        chi.pb(S);
        return;
    }
    for(int a=0;a<=2;a++){
        S[u]+=a;
        S[u+1]+=a;
        S[u+2]+=a;
        DFS(u+1);
        S[u]-=a;
        S[u+1]-=a;
        S[u+2]-=a;
    }
}

int MA[6666];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    DFS(0);
    //cout<<si(chi)<<endl;
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        vi A(N);
        for(int i=0;i<N;i++){
            cin>>A[i];A[i]--;
        }
        vvi Z(N+1,vi(8));
        for(int i=0;i<N;i++){
            Z[i+1]=Z[i];
            Z[i+1][A[i]]++;
        }
        ll ans=0;
        
        for(auto T:chi){
            vi used;
            vi sv(N+1);
            int s=0;
            for(int i=0;i<=N;i++){
                while(s<i){
                    bool ok=true;
                    for(int j=0;j<8;j++){
                        if(Z[i][j]-Z[s][j]<T[j]) ok=false;
                    }
                    if(!ok) break;
                    MA[sv[s]]++;
                    s++;
                }
                vi U(8);
                int ddd=0;
                for(int j=0;j<8;j++){
                    U[j]=(Z[i][j]-T[j]+333)%3;
                    ddd*=3;
                    ddd+=U[j];
                }
                ans+=MA[ddd];
                ddd=0;
                for(int j=0;j<8;j++){
                    U[j]=(Z[i][j])%3;
                    ddd*=3;
                    ddd+=U[j];
                }
                sv[i]=ddd;
                used.pb(ddd);
            }
            for(int a:used) MA[a]=0;
        }
        
        cout<<ans<<"\n";
    }
}



详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3672kb

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: