QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#847478#9922. Mah-jongfang_babyWA 2327ms3876kbC++235.0kb2025-01-08 00:13:522025-01-08 00:13:52

Judging History

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

  • [2025-01-08 00:13:52]
  • 评测
  • 测评结果:WA
  • 用时:2327ms
  • 内存:3876kb
  • [2025-01-08 00:13:52]
  • 提交

answer

/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define maxn 200005
mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()};
ll mod = 998244353;
ll MOD = 998244353;
//cout<<"panduan\n";
//auto dfs = [&](auto &self,int x,int f)->void{self(self,x,f);};




void solve(){
	
	int n = 0;
	cin>>n;
	vector<int>arr(n);
	vector<int>temp(729);
	for(int i = 0;i<n;i++){
		cin>>arr[i];
		arr[i]--;
	}
	int all[7] = {0};
	//all[0] = 1;
	ll ans = 0;
	for(int i = 0;i<729;i++){
	//int i = 1;	
		int num[8] = {0};
		vector<int>cnt(6561);
		for(int j = 0;j<6;j++){
			if(all[j]){
				num[j]-=all[j];
				num[j+1]-=all[j];
				num[j+2]-=all[j];
			}
		}
		//for(int j = 0;j<8;j++)cout<<num[j]<<"\n";
		
		int num2[8] = {0};
		int num3[8] = {0};
		int num4[8] = {0};
		for(int j = 0;j<8;j++){
			if(num[j]<3){
				num4[j] = -3;
			}else{
				num4[j] = 0;
			}
			//num4[j] = -3;
		}
		int ok2 = 1;
		int ok = 0;
		for(int k = 0;k<8;k++){
			if(num[k]<num4[k]){
				ok2 = 0;
				break;
			}
		}
		//if(ok2)
		cnt[0]++;
		for(int j = 0;j<n;j++){
			num2[arr[j]]++;
			num[arr[j]]++;
			if(num2[arr[j]]==3){
				num2[arr[j]] = 0;
			}
			ok = 1;
			ok2 = 1;
			
			for(int k = 0;k<8;k++){
				if(num[k]<num4[k]){
					ok2 = 0;
					break;
				}
			}
			
			for(int k = 0;k<8;k++){
				
				num3[k] = num2[k];
				if(num[k]<0){
					ok = 0;
					break;
				}
			}
			int haha = 0,te = 1;
			int haha2 = 0;
			for(int k = 0;k<6;k++){
				num3[k] = (num3[k]-all[k]+3)%3;
				num3[k+1] = (num3[k+1]-all[k]+3)%3;
				num3[k+2] = (num3[k+2]-all[k]+3)%3;
			}
			for(int k = 0;k<8;k++){
				haha+=num2[k]*te;
				haha2+=num3[k]*te;
				te*=3;
			}
			if(ok)ans+=cnt[haha2];
			if(ok2)cnt[haha]++;
			
		}
		
		
		all[0]++;
		int dex = 0;
		while(dex<=5&&all[dex]>=3){
			all[dex++] = 0;
			all[dex]++;
		}
	}

	cout<<ans<<"\n";

}




int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 1;
	cin>>t;
	while(t--){
		solve();
	}

	return 0;
}













Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2327ms
memory: 3876kb

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:

53168
63816
5460
2262
246142
6871
11714
47814
439519
1226505
18716
142311
303603
970531
222020
1587
88415
144234
70262
1
81417
0
40832
17966
88637
0
103385
165724
3
517582
59752
200307
27406
63449
29788
12289
2335
4969
75734
913443
176672
25391
783
90772
1312701
1590
12434
158055
12360
24383
25981
1...

result:

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