QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#856144 | #9922. Mah-jong | asdf__ | WA | 332ms | 46636kb | C++14 | 1.9kb | 2025-01-13 17:20:19 | 2025-01-13 17:20:19 |
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];
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(){
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]++;
}
}
}
int now=0;
memset(cn,0,sizeof(cn));
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){
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);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 44ms
memory: 25180kb
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: 332ms
memory: 46636kb
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:
145709 259315 94554 56645 1372768 200813 279921 802913 3099282 6641463 515130 2031738 3312099 7255960 3101269 178763 2247047 2973215 2322265 1 2357366 0 1711540 1184429 3040423 0 3306824 4555942 3 9202871 2400420 5972070 1981771 3312585 2364703 1425232 539099 993761 4093641 14088090 7040815 2757333 ...
result:
wrong answer 1st numbers differ - expected: '51699', found: '145709'