QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#849745 | #9922. Mah-jong | Crysfly | WA | 917ms | 191276kb | C++14 | 4.0kb | 2025-01-09 17:55:34 | 2025-01-09 17:55:35 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ull unsigned long long
//#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
#define mod 998244353
struct modint{
unsigned int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 1000005
#define inf 0x3f3f3f3f
int n,a[maxn],cnt[maxn][9];
int pw[233];
deque<int>q[10005];
int now[9];
vi qwq[10050];
int get(vi o){
int sta=0;
For(j,1,8) sta=sta*3+(o[j-1]%3);
return sta;
}
vector<int>qq;
void chk(){
int sta=0;
For(j,1,8) sta=sta*3+(now[j]%3);
vi os;
For(j,1,8) os.pb(now[j]);
qwq[sta]=os;
qq.pb(sta);
}
void dfs(int u){
if(u==7){
chk();
return;
}
For(i,0,2){
For(j,0,2)now[u+j]+=i;
dfs(u+1);
For(j,0,2)now[u+j]-=i;
}
}
void prew(){
dfs(1);
}
int lst[maxn];
ll res[maxn];
int sb[6666][6666];
void work()
{
n=read();
For(i,1,n)a[i]=read();
For(i,1,n){
For(j,1,8)cnt[i][j]=cnt[i-1][j];
cnt[i][a[i]]++;
}
For(j,0,pw[8]) q[j].clear(),lst[j]=-1,res[j]=0;
ll sum=0;
For(i,0,n){
int sta=0;
For(j,1,8)sta=sta*3+(cnt[i][j]%3);
// cout<<"sta "<<sta<<"\n";
for(auto S:qq){
assert(qwq[S].size());
int j=sb[sta][S];
if(lst[j]!=-1){
int l=lst[j];
bool ok=1;
For(k,1,8) if(cnt[i][k]-cnt[l][k]<qwq[S][k-1]) {
ok=0; break;
}
if(!ok) continue;
}
while(q[j].size()){
int l=q[j].front();
bool ok=1;
// cout<<"chk "<<l<<' '<<i<<endl;
For(k,1,8) if(cnt[i][k]-cnt[l][k]<qwq[S][k-1]) {
ok=0; break;
}
if(ok) lst[j]=l,q[j].pop_front(),++res[j];
else break;
}
sum+=res[j];
}
q[sta].pb(i);
}
cout<<sum<<"\n";
}
signed main()
{
pw[0]=1;
For(i,1,8) pw[i]=pw[i-1]*3;
prew();
For(i,0,pw[8]-1) for(int j:qq) {
int s=0;
For(k,0,7){
int t=(i/pw[7-k]%3)-(j/pw[7-k]%3)+3;
s=s*3+(t%3);
}
sb[i][j]=s;
}
// cout<<pw[8]<<endl;
int T=read();
while(T--)work();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 170ms
memory: 191276kb
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: 917ms
memory: 190384kb
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:
51639 61410 5142 1956 241394 6274 11218 46130 434808 1217854 17190 139400 299167 959358 217522 1174 87295 140962 69751 1 78807 0 39482 16734 86462 0 100200 161783 3 511570 58548 196757 26105 61563 28849 11499 2061 4390 74544 906497 172563 23928 524 87771 1303935 1413 11771 156218 11734 23183 25166 9...
result:
wrong answer 1st numbers differ - expected: '51699', found: '51639'