QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#841076 | #9922. Mah-jong | rqoi031 | WA | 2811ms | 190776kb | C++20 | 2.1kb | 2025-01-03 12:16:00 | 2025-01-03 12:16:00 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
typedef long long ll;
constexpr int N{100000},L{8},C{729};
constexpr int del[3]{1,1,-2};
int cnt[C+5][L];
int ptr[C+5],vcc[C+5][L],val[C+5],ccc[C+5][(1<<(L<<1))+5];
void init() {
int tot{0};
for(int i=0;i!=1<<(L-2<<1);i++) {
if([&]()->bool {
for(int j=0;j!=L-2;j++) {
if((i>>(j<<1)&3)>=3) {
return true;
}
}
return false;
}()) {
continue;
}
++tot;
std::fill(cnt[tot],cnt[tot]+L,0);
for(int j=0;j!=L-2;j++) {
int c{i>>(j<<1)&3};
cnt[tot][j]+=c;
cnt[tot][j+1]+=c;
cnt[tot][j+2]+=c;
}
}
for(int i=1;i<=C;i++) {
std::fill(ccc[i],ccc[i]+(1<<(L<<1)),0);
}
}
int a[N+5],c[N+5][L],v[N+5];
void solve() {
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d",a+i),--a[i];
}
ll ans{0};
std::fill(c[0],c[0]+L,0);
std::fill(ptr+1,ptr+C+1,0);
for(int i=1;i<=C;i++) {
val[i]=0;
for(int j=0;j!=L;j++) {
vcc[i][j]=(3-cnt[i][j]%3)%3;
val[i]|=vcc[i][j]<<(j<<1);
}
}
for(int i=1;i<=n;i++) {
std::copy(c[i-1],c[i-1]+L,c[i]);
v[i]=v[i-1]+(del[c[i][a[i]]++%3]<<(a[i]<<1));
for(int j=1;j<=C;j++) {
while(ptr[j]<i&&(ptr[j]==0?[&]()->bool {
for(int p=0;p!=L;p++) {
if(c[i][p]-c[ptr[j]][p]<cnt[j][p]) {
return false;
}
}
return true;
}():vcc[j][a[ptr[j]]]-1>=cnt[j][a[ptr[j]]])) {
++ccc[j][v[ptr[j]++]];
}
val[j]+=del[vcc[j][a[i]]++%3]<<(a[i]<<1);
ans+=ccc[j][val[j]];
}
}
for(int i=1;i<=C;i++) {
for(int j=0;j<=n;j++) {
ccc[i][v[j]]=0;
}
}
printf("%lld\n",ans);
}
int main() {
init();
int t;
scanf("%d",&t);
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 190776kb
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: 2811ms
memory: 190180kb
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:
54609 65042 5854 2431 248052 7099 12390 48686 443453 1233922 19137 143983 306754 973676 223658 1683 91312 145837 73070 1 82620 0 42055 18368 90259 0 104556 167081 3 521159 61743 202392 28255 64900 31114 12817 2487 5240 78099 919397 178792 26029 837 91971 1320309 1831 13069 161261 12904 25116 27136 1...
result:
wrong answer 1st numbers differ - expected: '51699', found: '54609'