QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#847417#9922. Mah-jongfang_babyRE 2ms3556kbC++234.8kb2025-01-07 23:01:242025-01-07 23:01:24

Judging History

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

  • [2025-01-07 23:01:24]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3556kb
  • [2025-01-07 23:01:24]
  • 提交

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++){
			num4[j] = num[j]%3;
		}
		int ok2 = 0;
		int ok = 0;
		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[j]<num4[j]){
					ok2 = 0;
				}
				
				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: 3556kb

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
Runtime Error

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: