QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848564 | #9922. Mah-jong | isWFnoya# | WA | 535ms | 8124kb | C++23 | 2.2kb | 2025-01-08 22:05:40 | 2025-01-08 22:05:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
typedef long long ll;
typedef pair<ll,ll> PII;
int n,m,k;
ll a[N],b[N],c[N],dep[N];
// char s[N];
int tr[N][26];
int s[N];
int idx=0;
ll ans;
set<int> able;
int now[10],now2[10];
void dfs(int x){
if(x==8){
int state=0;
for(int i=7;i>=0;i--) state=state*3+b[i];
for(int i=0;i<8;i++) c[i]=b[i];
for(int i = 0 ; i < 8 ; i ++)
{
if(c[i] < 0) return;
a[i] %= 3 ;
if(c[i] > 0)
{
if(i + 2 >= 8) return;
c[i + 1] -= c[i] ;
c[i + 2] -= c[i] ;
}
}
// cout<<state<<endl;
able.insert(state);
}else{
for(int i=0;i<3;i++){
b[x]=i;
dfs(x+1);
}
}
}
void __(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
a[i]--;
}
s[0]=0;
memset(now,0,sizeof now);
for(int i=1;i<=n;i++){
now[a[i]]++;
now[a[i]]%=3;
s[i]=0;
for(int j=7;j>=0;j--){
s[i]=s[i]*3+now[j];
}
// cout<<s[i]<<" ";
}
// cout<<endl;
ll ans=0;
map<int,int> mp;
mp[s[n]]=1;
for(int i=n-1;i>=0;i--){
int t=s[i];
for(int k=0;k<8;k++){
now[k]=t%3;
t/=3;
}
for(auto j:able){
int jj=j;
for(int k=0;k<8;k++){
now2[k]=j%3;
j/=3;
}
// for(int k=0;k<8;k++){
// now[k]=(now[k]+now2[k])%3;
// }
int res=0;
for(int k=7;k>=0;k--){
res=res*3+(now[k]+now2[k])%3;
}
if(mp.count(res)){
// cout<<s[i]<<" "<<jj<<" "<<res<<" "<<mp[res]<<endl;
ans+=mp[res];
}
}
mp[s[i]]++;
}
printf("%lld\n",ans);
}
//2*1 1*2
//2 2 2
int main(){
dfs(0);
// cout<<able.size()<<endl;
int _=1;
cin>>_;
while(_--){
__();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7896kb
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: 535ms
memory: 8124kb
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'