QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#830252 | #9922. Mah-jong | CQXYM# | WA | 542ms | 20608kb | C++23 | 1.7kb | 2024-12-24 17:24:21 | 2024-12-24 17:24:22 |
Judging History
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;
constexpr int N=1<<24;
bool val[N];
signed main(){
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;
};
for(int i=0;i<N;++i){
val[i]=valid(i);
}
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}});
ll ans=0;
for(int i=0;i<n;++i){
int&x=a[i];
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});
if(!(i%15)){
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(val[st])ans+=cnt;
}
// cerr<<ssize(f)<<'\n';
}
printf("%lld\n",ans-n);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 112ms
memory: 20108kb
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: 542ms
memory: 20608kb
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:
15544 18843 1663 730 73513 2035 3831 14191 130127 362089 5566 42549 90604 285482 66007 484 27641 42495 21518 1 24603 0 12227 5120 25673 0 30160 49481 3 153795 17955 59222 8144 18967 9004 3647 710 1543 23110 269955 52899 7608 245 26950 389185 596 3803 47438 3707 7308 7910 3212 97857 124 214 5541 3390...
result:
wrong answer 1st numbers differ - expected: '51699', found: '15544'