QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#835496#9922. Mah-jongucup-team5318#WA 1961ms12304kbC++142.1kb2024-12-28 12:19:442024-12-28 12:19:49

Judging History

This is the latest submission verdict.

  • [2024-12-28 12:19:49]
  • Judged
  • Verdict: WA
  • Time: 1961ms
  • Memory: 12304kb
  • [2024-12-28 12:19:44]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+5,M=15,K=1e4+5,S=(1<<8)+5;
int T,n,a[N];
int st[K][9],iscor[K][S],tot,b[10],d[10];
map<vector<int>,int>mp;
void dfs1(int step) {
	if(step==9)
	{
		for(int i=0;i<(1<<8);i++) {
			for(int j=1;j<=8;j++)b[j]=((i>>j-1)&1)*3+a[j];
			for(int i=1;i<=9;i++)d[i]=b[i]-b[i-1];
			if((d[1]+d[4]+d[7])!=0)continue;
			if((d[2]+d[5]+d[8])!=0)continue;
			if((d[3]+d[6]+d[9])!=0)continue;
			if(d[1]<0 || d[2]<0 || d[3]<0 || d[7]>0 || d[8]>0 || d[9]>0)continue;
			vector<int>now(8);
			for(int i=1;i<=8;i++)now[i-1]=a[i];
			if(!mp.count(now)) {
				tot++,mp[now]=tot;
				for(int j=1;j<=8;j++)st[tot][j]=b[j];
			}
			int ns=mp[now];
			iscor[ns][i]=1;
		}
		return ;
	}
	for(int i=0;i<3;i++)a[step]=i,dfs1(step+1);
}
void init() {
	dfs1(1);
	//tot=1;
	for(int i=1;i<=tot;i++)
		for(int j=0;j<8;j++)for(int k=0;k<(1<<8);k++)if((k>>j)&1)iscor[i][k]|=iscor[i][k^(1<<j)];
}
vector<int>pos[K];
int sum[N][9],L[K];
void solve() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0;i<=1e4;i++)pos[i].clear(),L[i]=n+1;
	for(int i=0;i<=n;i++) {
		if(i>0) {
			for(int j=1;j<=8;j++)sum[i][j]=sum[i-1][j];
			sum[i][a[i]]++;
		}
		vector<int>now(8);int st=0;
		for(int j=1;j<=8;j++)now[j-1]=sum[i][j]%3,st=st*3+now[j-1];
		pos[st].push_back(i);
	}
	ll ans=0;
	//exit(0);
	for(int i=n;i;i--) {
		for(int j=1;j<=tot;j++) {
			while(L[j]>i+1) {
				int S=0;
				for(int k=1;k<=8;k++)S|=(sum[L[j]-1][k]-sum[i-1][k]>=3);
				if(iscor[j][S])L[j]--;else break;
			}
			vector<int>now(8);
			int vv=0;
			for(int k=1;k<=8;k++)now[k-1]=(st[j][k]+sum[i-1][k]+3)%3;
			//cerr<<'\n';
			for(int k=0;k<8;k++)vv=vv*3+now[k];
			//cerr<<'\n';
			auto&c=pos[vv];
			//cerr<<i<<' '<<j<<' '<<L[j]<<' '<<c.size()<<'\n';
			ans+=c.end()-lower_bound(c.begin(),c.end(),L[j]);
			//cerr<<ans<<'\n';
		}
	}cout<<ans<<'\n';
}
int main() {
	#ifndef ONLINE_JUDGE
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
	#endif 
	init();
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 23ms
memory: 9936kb

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: 1961ms
memory: 12304kb

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:

5694
7070
616
268
26028
778
1283
5018
46691
128864
1938
15082
32608
100853
23516
198
9423
15243
7779
1
8633
0
4479
1952
9346
0
11167
17750
1
54471
6711
20965
2994
6771
3317
1301
283
620
8320
95598
18744
2774
103
9598
138112
201
1354
16983
1470
2685
2877
1160
35786
57
81
1901
12155
3339
569
54260
345...

result:

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