QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83573 | #1286. Ternary String Counting | eyiigjkn | WA | 2ms | 3576kb | C++14 | 2.0kb | 2023-03-02 16:29:04 | 2023-03-02 16:29:05 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int cof[]={1,3,6,6},mod=1e9+7;
int L1[5010],L2[5010],R1[5010],R2[5010],f[5010][5010],s1[5010],s2[5010];
template<typename T>
inline void upd(int &x,const T &y){x=(x+y)%mod;}
inline void chkmin(int &x,const int &y){x=(x<y?x:y);}
inline void chkmax(int &x,const int &y){x=(x>y?x:y);}
int solve()
{
int n,m,l,r,x,x1=0,x2=0,y1=0,y2=0,ans=0;
scanf("%d%d",&n,&m);
fill(L1+1,L1+n+1,0);
fill(L2+1,L2+n+1,0);
iota(R1+1,R1+n+1,0);
iota(R2+1,R2+n+1,0);
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&l,&r,&x);
if(x==1) chkmin(R1[r],l-1),chkmin(R2[r],l-1);
else if(x==2) chkmax(L1[r],l),chkmin(R2[r],l-1);
else chkmax(L1[r],l+1),chkmax(L2[r],l);
}
for(int i=2;i<=n;i++) chkmax(L1[i],L1[i-1]),chkmax(L2[i],L2[i-1]);
for(int i=n-1;i;i--) chkmin(R1[i],R1[i+1]),chkmin(R2[i],R2[i+1]);
for(int i=1;i<=n;i++)
if(L1[i]>R1[i] || L2[i]>R2[i])
return 0;
s1[0]=s2[0]=f[0][0]=1;
for(int i=0;i<n;i++)
{
for(int j=max(x1,1);j<=x2;j++)
{
int v=s1[j];
upd(f[i][j],v);
if(i>=y1 && i<=y2) upd(s1[i],v),upd(s2[j],v);
}
if(i) for(int j=y1;j<=y2;j++)
{
int v=s2[j];
upd(f[i][j],v);
if(i>=x1 && i<=x2) upd(s1[i],v),upd(s2[j],v);
}
for(;x1<L1[i+1];x1++)
for(int j=y1;j<=y2;j++)
upd(s1[x1],mod-f[x1][j]),upd(s2[j],mod-f[x1][j]);
for(;x2<R1[i+1];x2++)
for(int j=y1;j<=y2;j++)
upd(s1[x2+1],f[x2+1][j]),upd(s2[j],f[x2+1][j]);
for(;y1<L2[i+1];y1++)
for(int j=x1;j<=x2;j++)
upd(s1[j],mod-f[j][y1]),upd(s2[y1],mod-f[j][y1]);
for(;y2<R2[i+1];y2++)
for(int j=x1;j<=x2;j++)
upd(s1[j],f[j][y2+1]),upd(s2[y2+1],f[j][y2+1]);
}
for(int i=x1;i<=x2;i++)
for(int j=y1;j<=y2;j++)
upd(ans,(ll)f[i][j]*cof[(i>0)+(j>0)+1]);
for(int i=0;i<=n;i++) memset(f[i],0,sizeof(int)*(n+1));
memset(s1,0,sizeof(int)*(n+1));
memset(s2,0,sizeof(int)*(n+1));
return ans;
}
int main()
{
int T;
cin>>T;
while(T--) printf("%d\n",solve());
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3512kb
input:
4 1 0 2 0 3 0 5 2 1 3 3 4 5 1
output:
3 9 27 18
result:
ok 4 tokens
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3576kb
input:
741 5 3 1 5 3 3 4 2 1 4 3 4 3 2 4 2 1 4 1 2 3 3 10 3 9 10 2 3 6 3 1 9 1 3 4 2 3 2 1 3 2 2 3 3 1 3 3 10 4 6 6 1 9 10 2 4 8 3 4 10 3 6 3 1 4 3 2 4 2 2 2 2 4 3 1 4 1 1 1 2 2 3 1 5 3 4 5 2 4 5 1 1 4 3 9 3 2 3 2 1 9 2 2 4 2 4 3 1 3 3 2 3 2 1 2 3 8 4 5 8 1 4 8 1 3 5 3 1 3 3 9 3 4 5 1 1 5 3 3 8 2 8 3 5 7 2...
output:
90 0 0 0 24300 0 0 0 768 0 0 2184 3402 0 10368 3396 0 0 0 0 0 0 0 0 6 0 0 0 0 0 96 0 6 0 0 0 0 0 0 0 126 0 0 0 2916 0 0 0 0 0 0 0 0 0 0 648 8748 0 0 0 0 0 0 10764 0 0 0 18 0 0 0 0 0 0 0 0 0 0 0 1992 0 0 1818 72 162 2196 0 0 0 0 108 54 0 48 0 0 0 0 1464 0 3000 432 0 0 144 312 0 0 264 6 366 0 60 0 0 0...
result:
wrong answer 12th words differ - expected: '972', found: '2184'