QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697822 | #1286. Ternary String Counting | little_pinkpig | WA | 1ms | 3912kb | C++14 | 2.3kb | 2024-11-01 15:54:17 | 2024-11-01 15:54:18 |
Judging History
answer
#include<bits/stdc++.h>
#define pi pair<int,int>
#define fi first
#define se second
#define MAXS (5005)
using namespace std;
const int mod=1000000007;
template<typename type>
void read(type &x)
{
bool f=0;char ch=0;x=0;
while(ch<'0'||ch>'9'){f|=!(ch^'-');ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
x=f?-x:x;
}
template<typename type,typename... Args>
void read(type &x,Args &... args)
{
read(x);
read(args...);
}
int test,n,m,limj,ans;
int rs[MAXS],cs[MAXS],mn_j[MAXS],mn_k[MAXS],mx_j[MAXS],mx_k[MAXS],sl[MAXS],sr[MAXS],f[MAXS][MAXS],g[MAXS];
inline void del(int x,int y)
{
rs[x]=(rs[x]-f[x][y]+mod)%mod;
cs[y]=(cs[y]-f[x][y]+mod)%mod;
f[x][y]=0;
}
void clr(int pos)
{
for(int i=limj;i<pos;i++)
{
if(i<mn_j[pos]||i>mx_j[pos])
{
for(int j=0;j<=n;j++) del(i,j);
sl[i]=n,sr[i]=0;
}
else
{
for(int j=sl[i];j<mn_k[pos];j++) del(i,j);
for(int j=sr[i];j>mx_k[pos];j--) del(i,j);
sl[i]=max(sl[i],mn_k[pos]);
sr[i]=min(sr[i],mx_k[pos]);
}
}
limj=max(limj,mn_j[pos]);
}
inline void solve()
{
read(n,m);
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=0;
for(int i=1;i<=n;i++) rs[i]=cs[i]=0,mn_j[i]=mn_k[i]=0,mx_j[i]=mx_k[i]=n,sl[i]=0,sr[i]=n;
for(int i=1,l,r,x;i<=m;i++)
{
read(l,r,x);
if(x==1) mx_j[r]=min(mx_j[r],l-1);
else if(x==2) mn_j[r]=max(mn_j[r],l),mx_k[r]=min(mx_k[r],l-1);
else mn_j[r]=max(mn_j[r],l+1),mn_k[r]=max(mn_k[r],l);
}
limj=0;
f[0][0]=1,cs[0]=rs[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<i;j++) g[j]=(rs[j]+cs[j])%mod;
if(mn_j[i]<i&&mx_j[i]>=i-1)
{
for(int j=mn_k[i];j<=min(mx_k[i],max(0,i-2));j++)
{
f[i-1][j]=(f[i-1][j]+g[j])%mod;
cs[j]=(cs[j]+g[j])%mod;
rs[i-1]=(rs[i-1]+g[j])%mod;
}
}
clr(i);
}
ans=0;
for(int i=0;i<=n;i++) ans=(ans+rs[i])%mod;
printf("%d\n",ans);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
read(test);
for(int i=1;i<=test;i++) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3912kb
input:
4 1 0 2 0 3 0 5 2 1 3 3 4 5 1
output:
3 9 27 999999953
result:
wrong answer 4th words differ - expected: '18', found: '999999953'