QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#830235#9922. Mah-jongCQXYM#TL 0ms3756kbC++171.6kb2024-12-24 17:14:582024-12-24 17:14:58

Judging History

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

  • [2024-12-24 17:14:58]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3756kb
  • [2024-12-24 17:14:58]
  • 提交

answer

#pragma GCC optimize("Ofast,inline,unroll-loops")
#include<bits/stdc++.h>
void debug_(const auto&...a){
	((std::cerr<<a<<' '),...)<<'\n';
}
#define debug(A...) debug_(__LINE__,':',#A,'=',A)
using ll=long long;
#define all(s) std::begin(s),std::end(s)
using namespace std;
template<typename T>using V=std::vector<T>;
#define eb emplace_back
#define pb push_back
using pii=std::pair<int,int>;
using Info=int;
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		V<int>a(n);
		// for(int i=0;i<n;++i)a[i]=i%8+1;
		for(auto&x:a)cin>>x,--x;
		using S=std::pair<Info,ll>;
		V<S>f({{0,1}});
		auto valid=[&](auto st){
			static int a[8];
			for(int i=0;i<8;++i){
				a[i]=st>>(i*3)&7;
			}
			for(int i=0;i<8;++i){
				if(a[i]<0)return false;
				a[i]%=3;
				if(a[i]){
					if(i+2>=8)return false;
					a[i+1]-=a[i];
					a[i+2]-=a[i];
				}
			}
			return true;
		};
		ll ans=0;
		for(auto&x:a){
			for(auto&[st,cnt]:f){
				// st[x]++;
				// if(st[x]>=7){
					// st[x]-=3;
				// }
				st+=1<<(x*3);
				if((st>>(x*3)&7)==7){
					st&=~(7<<(x*3));
				}
			}
			f.pb({0,1});
			sort(all(f));
			{
				auto first=begin(f),last=end(f);
			 
			    auto result = first;
			    while (++first != last)
			        if (result->first!=first->first){
			        	if(++result != first)*result = std::move(*first);
			        }else{
			        	result->second+=first->second;
			        }
			    f.erase(++result,last);
			}
			for(auto&[st,cnt]:f){
				if(valid(st))ans+=cnt;
			}
			// cerr<<ssize(f)<<'\n';
		}
		printf("%lld\n",ans-n);
	}
}

详细

Test #1:

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

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: