QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#856536 | #9922. Mah-jong | asdf__ | WA | 380ms | 46604kb | C++14 | 2.2kb | 2025-01-14 10:03:17 | 2025-01-14 10:03:18 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=1e5+5,M=729+5,V=6561+5;
int n,T,la[M],cn[15],an[M][15],cnt,su,a[N],ans[9*M],no[M][15],zf[9],da[V][M];
bool pd[M];
vector<int> b[N];
void dfs(int g){
if(g==7){
cnt++;
for(int i=1;i<=8;i++) an[cnt][i]=cn[i];
return;
}
dfs(g+1);
for(int i=0;i<3;i++) cn[g+i]++;
dfs(g+1);
for(int i=0;i<3;i++) cn[g+i]++;
dfs(g+1);
for(int i=0;i<3;i++) cn[g+i]-=2;
}
void dfs1(int g){
if(g==9){
int ans=0;
for(int j=1;j<=8;j++) ans+=zf[j]*cn[j];
for(int i=1;i<=cnt;i++){
int ans1=0;
for(int j=1;j<=8;j++) ans1+=(cn[j]-an[i][j]+3)%3*zf[j];
da[ans][i]=ans1;
}
return;
}
dfs1(g+1);
cn[g]++;
dfs1(g+1);
cn[g]++;
dfs1(g+1);
cn[g]-=2;
}
int main(){
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
memset(cn,0,sizeof(cn));
zf[1]=1;
for(int i=2;i<=8;i++) zf[i]=zf[i-1]*3;
scanf("%d",&T);
dfs(1);
dfs1(1);
while(T--){
scanf("%d",&n);
b[0].clear();
for(int i=1;i<=n;i++){
b[i].clear();
scanf("%d",&a[i]);
}
for(int i=1;i<=cnt;i++){
la[i]=1;
memset(cn,0,sizeof(cn));
cn[a[1]]=1;
for(int j=1;j<=8;j++){
while(cn[j]<an[i][j] && la[i]<=n){
cn[a[la[i]+1]]++;
la[i]++;
}
}
// if(la[i]!=n+1) printf("%d %d\n",i,la[i]);
}
int now=0;
memset(cn,0,sizeof(cn));
memset(pd,0,sizeof(pd));
for(int i=1;i<=n;i++){
now-=zf[a[i]]*cn[a[i]];
cn[a[i]]=(cn[a[i]]+1)%3;
now+=zf[a[i]]*cn[a[i]];
for(int j=1;j<=cnt;j++){
no[j][a[i]]++;
if(la[j]<=i){
if(!pd[j]) pd[j]=la[j]=1;
while(no[j][a[la[j]]]>an[j][a[la[j]]] && la[j]<i){
no[j][a[la[j]]]--;
la[j]++;
}
b[la[j]-1].push_back(da[now][j]);
}
}
}
now=0;
long long ans1=0;
memset(ans,0,sizeof(ans));
memset(cn,0,sizeof(cn));
for(int i=0;i<n;i++){
now-=zf[a[i]]*cn[a[i]];
cn[a[i]]=(cn[a[i]]+1)%3;
now+=zf[a[i]]*cn[a[i]];
ans[now]++;
for(int j=0;j<(int)b[i].size();j++) ans1+=ans[b[i][j]];
}
printf("%lld\n",ans1);/*
if(ans1==7){
freopen("2.out","w",stdout);
printf("1\n10\n");
for(int i=1;i<=10;i++) printf("%d ",a[i]);
freopen("1.out","w",stdout);
}*/
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 44ms
memory: 25172kb
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: 380ms
memory: 46604kb
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:
127984 150826 30790 14680 456414 37786 50027 140394 709265 1715581 63936 301370 545107 1412119 425348 13958 229155 320983 207097 1 225668 0 152996 94018 275411 0 313999 444228 3 1155701 230978 613328 165056 286825 188621 106476 36898 68160 325483 1686036 581401 184936 7736 374539 2401188 32495 95722...
result:
wrong answer 1st numbers differ - expected: '51699', found: '127984'