QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#338997 | #7219. The Mighty Spell | Kevin5307 | WA | 3ms | 10808kb | C++20 | 1.1kb | 2024-02-26 16:17:45 | 2024-02-26 16:17:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int c[200200],n,m;
int cnt[200200][55];
ll pw2[200200],g[200200],pg[200200];
int nxt[200200][55];
int main()
{
pw2[0]=1;
for(int i=1;i<200200;i++)
pw2[i]=pw2[i-1]*2%mod;
for(int i=0;i<200200;i++)
g[i]=(2ll*i*i*i+3ll*i*i+3*i+3)%mod;
for(int i=1;i<200200;i++)
pg[i]=(pg[i-1]+g[i])%mod;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>c[i];
for(int j=1;j<=m;j++)
nxt[n+1][j]=n+1;
for(int i=n;i>=1;i--)
for(int j=1;j<=m;j++)
nxt[i][j]=(c[i]==j?i:nxt[i+1][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cnt[i][j]=cnt[i-1][j]+(c[i]==j);
ll ans=0;
for(int i=1;i<=n;i++)
{
static int vis[55];
memset(vis,0,sizeof(vis));
int j=i;
while(j<=n)
{
vis[c[j]]=1;
ll ways=1;
for(int c=1;c<=m;c++)
{
int tot=cnt[max(0,i-2)][c]+cnt[n][c]-cnt[min(n,j+1)][c];
ways=ways*(pw2[tot]-1+vis[c])%mod;
}
int nj=n+1;
for(int c=1;c<=m;c++)
if(!vis[c])
nj=min(nj,nxt[j+1][c]);
ans=(ans+ways*(pg[nj-i]-pg[j-i]+mod))%mod;
j=nj;
}
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 10160kb
input:
3 2 1 2 2
output:
152
result:
ok answer is '152'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9648kb
input:
4 3 1 2 1 2
output:
0
result:
ok answer is '0'
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 10808kb
input:
6 3 1 2 3 3 2 1
output:
7307
result:
wrong answer expected '3627', found '7307'