QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#857005 | #9922. Mah-jong | zhuge0 | WA | 0ms | 5708kb | C++20 | 2.8kb | 2025-01-14 23:08:04 | 2025-01-14 23:08:05 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 20020219, inf = 1e18;
ll n, m, k, q,l,r,ans=0,all=0;
vector<int> mmp[50005]{};
deque<ll> que[10]{};
ll arr[200005]{};
int num[19]{},pw[10]{};
vector<int> pre(9),suf(9),temp(9);
void work()
{
pw[0]=1;
for(int i=1;i<=9;i++)
{
pw[i]=pw[i-1]*3;
}
}
void dfs(int depth,int st,ll pos,bool tag,int loc)
{
if(depth==7)
{ auto iter=lower_bound(mmp[st].begin(),mmp[st].end(),pos);
//for(auto i:mmp[st]) cout<<i<<'b'<<*iter<<"iter";
//cout<<'\n';
if(tag&&mmp[st].size())
{cout<<st<<' '<<loc<<' ';
for(auto i:mmp[st]) cout<<i<<' ';
cout<<'\n';
}ans+=max(0,(int)(iter-mmp[st].begin()));
return ;
}
//cout<<st;
//cout<<depth<<' ';
for(int i=0;i<=min({2,pre[depth],pre[depth+1],pre[depth+2]});i++)
{
int nst=st;
if(i)
{
if(pre[depth]%3>=i) nst-=i*pw[depth];
else nst+=(3-i)*pw[depth];
if(pre[depth+1]%3>=i) nst-=i*pw[depth+1];
else nst+=(3-i)*pw[depth+1];
if(pre[depth+2]%3>=i) nst-=i*pw[depth+2];
else nst+=(3-i)*pw[depth+2];
}
//cout<<nst<<'\n';
pre[depth]-=i,pre[depth+1]-=i,pre[depth+2]-=i;
num[depth]+=i,num[depth+1]+=i;num[depth+2]+=i;
ll npos=inf;
if(i)
npos=min({npos,que[depth][num[depth]-1],que[depth+1][num[depth+1]-1],que[depth+2][num[depth+2]-1]});
dfs(depth+1,nst,npos,tag,loc);
pre[depth]+=i,pre[depth+1]+=i,pre[depth+2]+=i;
num[depth]-=i,num[depth+1]-=i;num[depth+2]-=i;
}
}
void solve() {
for(int i=0;i<=50000;i++) mmp[i].clear();
for(int i=1;i<=8;i++) que[i].clear();
cin>>n;
all=0;
for(int i=1;i<=n;i++)
{
cin>>arr[i];
}
for(int i=0;i<9;i++) pre[i]=0;
ans=0;
mmp[0].push_back(0);
int state=0;
for(int i=1;i<=n;i++)
{ // cout<<arr[i]<<'a';
que[arr[i]].push_front(i);
while(que[arr[i]].size()>=6) que[arr[i]].pop_back();
pre[arr[i]]++;
if(pre[arr[i]]%3==0) state-=2*pw[arr[i]];
else state+=pw[arr[i]];
all=state;
dfs(1,all,inf,i==39,i);
mmp[state].push_back(i);
cout<<i<<":";
for(int j=1;j<=8;j++) cout<<pre[j]<<' ';
cout<<'\n';
}
cout<<ans<<'\n';
}
int main() {
//ios::sync_with_stdio(false);
//cin.tie(0);
work();
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
/*
1
39
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
见鬼了
qoj上这组数据31-39区间明明是有解的 但是标程既然算出来不算在内 难道哪里读错了?
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5708kb
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:
1:1 0 0 0 0 0 0 0 2:2 0 0 0 0 0 0 0 3:3 0 0 0 0 0 0 0 4:4 0 0 0 0 0 0 0 2 1:1 0 0 0 0 0 0 0 2:1 1 0 0 0 0 0 0 3:1 1 1 0 0 0 0 0 4:2 1 1 0 0 0 0 0 5:2 2 1 0 0 0 0 0 6:2 2 2 0 0 0 0 0 5 1:0 0 0 0 0 1 0 0 2:0 0 0 0 1 1 0 0 3:0 0 0 0 1 1 0 1 4:0 0 0 0 1 1 1 1 5:0 0 0 0 1 2 1 1 6:0 0 1 0 1...
result:
wrong output format Expected integer, but "1:1" found