QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638205#7006. Rikka with SubsequencesXY_ElevenAC ✓695ms140128kbC++232.5kb2024-10-13 15:11:372024-10-13 15:11:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 15:11:39]
  • 评测
  • 测评结果:AC
  • 用时:695ms
  • 内存:140128kb
  • [2024-10-13 15:11:37]
  • 提交

answer

#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define DB double
#define cint const int
#define cLL const long long
#define For(e,e1,e2) for(int e=(e1);e<=(e2);e++)
#define For_(e,e1,e2) for(int e=(e1);e<(e2);e++)
#define Rof(e,e1,e2) for(int e=(e2);e>=(e1);e--)
#define Rof_(e,e1,e2) for(int e=(e2);e>(e1);e--)
#define vct vector
#define ft first
#define sc second
#define pb push_back
#define pii pair<int,int>
#define pli pair<long long,int>
#define exc(e) if(e) continue
#define ret(e) if(e) return 
#define stop(e) if(e) break
#define sz(e) ((int)e.size())
using namespace std;

void main_init()
{
    
}
cint N=210;
int n,m;
int a[N],cnt[N],fin[N];
bitset <N> b[N];
char str[N];
cLL mod=1000000007ll;
LL dp[N][N][N],sum[N][N][N],s[N][N];
void main_solve()
{
    scanf("%d",&n);
    For(i,1,n) scanf("%d",&a[i]),cnt[a[i]]++;
//  n=200;
//  For(i,1,n) a[i]=(rand()%100<40?i:1),cnt[a[i]]++;
    m=0;
    For(i,1,n)
        if(cnt[i])
            fin[i]=++m;
//  printf("m=%d\n",m);
    For(i,1,n) a[i]=fin[a[i]];
    For(i,1,n)
    {
        scanf("%s",str+1);
//      For(j,1,n) str[j]='1';
        For(j,1,n) b[fin[i]][fin[j]]=(int)(str[j]=='1');
    }
    LL ans=0ll;
    For(i,1,n) For(j,1,n) For(k,1,n) dp[i][j][k]=0ll;
    For(i,1,m) For(j,1,n) For(k,1,n) sum[i][j][k]=0ll;
    For(i,1,n)
    {
        For(j,1,n) For(k,1,n) s[j][k]=0ll;
        For(j,1,n) For(k,1,n)
        {
            exc(a[i]!=a[j]||a[j]!=a[k]);
            if(i<=j&&j<=k)
            {
                dp[i][j][k]=1ll;
                For(c,1,m) if(b[c][a[i]])
                    dp[i][j][k]+=sum[c][j-1][k-1];
                dp[i][j][k]%=mod; if(dp[i][j][k]<0ll) dp[i][j][k]+=mod;
            }
            else
            {
                int i2=i,j2=j,k2=k;
                if(i2>j2) swap(i2,j2); if(i2>k2) swap(i2,k2); if(j2>k2) swap(j2,k2);
                dp[i][j][k]=dp[i2][j2][k2];
            }
//          printf("%d,%d,%d:%lld\n",i,j,k,dp[i][j][k]);
            ans+=dp[i][j][k]; 
            s[j][k]+=dp[i][j][k];
        }
        For(j,1,n) For(k,1,n)
        {
            s[j][k]+=(s[j-1][k]+s[j][k-1]-s[j-1][k-1]);
            sum[a[i]][j][k]+=s[j][k]; sum[a[i]][j][k]%=mod;
            if(sum[a[i]][j][k]<0ll) sum[a[i]][j][k]+=mod;
        }
    }
    printf("%lld\n",ans%mod);
}
int main()
{
//  freopen("ex_A4.in","r",stdin);
    main_init();
   int _; scanf("%d",&_); while(_--)
        main_solve();
    return 0;
}
/*

*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7916kb

input:

1
4
1 2 1 2
1111
1111
1111
1111

output:

51

result:

ok single line: '51'

Test #2:

score: 0
Accepted
time: 695ms
memory: 140128kb

input:

20
195
4 5 4 3 2 4 3 5 1 5 4 3 4 3 1 5 4 4 5 2 2 2 2 4 1 5 3 4 1 1 1 2 1 1 5 5 4 5 4 5 5 4 5 2 1 2 5 4 5 1 1 3 1 2 2 3 3 5 2 3 3 1 4 4 2 4 2 4 3 4 1 1 1 4 3 5 1 1 3 2 2 5 1 3 1 5 1 5 5 3 5 3 3 2 5 1 3 2 4 1 5 5 1 3 3 2 4 2 3 3 3 4 1 3 3 3 5 5 1 1 4 2 5 1 2 5 4 3 5 1 5 5 5 4 2 2 5 3 2 3 4 1 3 2 1 5 3...

output:

806298135
541285042
48173297
222851978
875793336
100057791
156057874
129923599
551277543
874547790
544405786
653241411
521317929
370918040
803940504
969296122
806596012
469227084
338962879
194278629

result:

ok 20 lines