QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763721#7006. Rikka with SubsequencesxlwangAC ✓426ms4272kbC++142.1kb2024-11-19 21:46:562024-11-19 21:46:57

Judging History

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

  • [2024-11-19 21:46:57]
  • 评测
  • 测评结果:AC
  • 用时:426ms
  • 内存:4272kb
  • [2024-11-19 21:46:56]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
const int Maxn=2e2+10,mod=1e9+7;
inline int ksm(int x,int y=mod-2){
    int sum=1;
    while(y){
        if(y&1) sum=1ll*sum*x%mod;
        y=y/2;x=1ll*x*x%mod;
    }return sum;
}
inline void add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
int a[Maxn],e[Maxn][Maxn];
int f[Maxn][Maxn],g[Maxn][Maxn];
int n;
char ch[Maxn];
inline int Add(int x,int y){x+=y;if(x>=mod) x-=mod;return x;}
inline void work(){
    n=read();
    fr(i,1,n) a[i]=read();
    fr(i,1,n){
        scanf("%s",ch+1);
        fr(j,1,n) e[i][j]=ch[j]-'0';
    }
    int ans=0;
    fr(i,1,n) fr(j,1,n) f[i][j]=g[i][j]=0;
    fr(i,1,n){
        fr(j,1,n) fr(k,1,n) f[j][k]=Add(Add(f[j][k],f[j-1][k]),Add(f[j][k-1],mod-f[j-1][k-1]));
        fr(j,1,n) fr(k,1,n) if(a[j]==a[k] && e[a[i-1]][a[j]]) add(g[j][k],f[j-1][k-1]);
        fr(j,1,n) fr(k,1,n){
            if(a[i]==a[k] && a[i]==a[j]){
                f[j][k]=(g[j][k]+1)%mod;
                add(ans,f[j][k]);
            }
            else f[j][k]=0;
        }
    }writeln(ans);
}
inline void init(){
	int t=read();
	while(t--) work();
}

signed main(){
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
    init();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3924kb

input:

1
4
1 2 1 2
1111
1111
1111
1111

output:

51

result:

ok single line: '51'

Test #2:

score: 0
Accepted
time: 426ms
memory: 4272kb

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