QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672632 | #7006. Rikka with Subsequences | FreeTimeLove | AC ✓ | 583ms | 4240kb | C++14 | 1.5kb | 2024-10-24 17:53:03 | 2024-10-24 17:53:04 |
Judging History
answer
/*FreeTimeLove's code.
Love has a nasty habit of disappearing over night.*/
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=205;
inline int rd(){
int ans=0,f=0;
char ch=getchar();
while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
re f?-ans:ans;
}
const int mod=1e9+7;
int n,f[N][N],a[N],S[N][N];
char s[N][N];
inline void MD(int &x){if(x>=mod)x-=mod;}
inline void ad(int &x,int y){x+=y;MD(x);}
int main(){
int T=rd();
while(T--){
n=rd();
for(int i=1;i<=n;i++)a[i]=rd();
for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
memset(f,0,sizeof f);
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++){
int &x=S[j+1][k+1];
x=S[j][k+1]+S[j+1][k]-S[j][k];
if(x<0)x+=mod;
MD(x);
if(s[a[j]][a[i]]=='1')ad(x,f[j][k]);
// S[j][k]=(S[j-1][k]+S[j][k-1]-S[j-1][k-1]+mod+(a[i]==a[j])*f[j][k])%mod;
}
for(int j=1;j<=n;j++){
if(a[i]!=a[j])con;
for(int k=1;k<=n;k++){
if(a[i]!=a[k])con;
ans+=S[j][k]+1;
ad(f[j][k],S[j][k]+1);
}
}
}
printf("%lld\n",ans%mod);
}
re 0;
}
/*
1
2
1 1
11
11
1
4
1 2 1 2
1111
1111
1111
1111
*/
}int main(){re FRTMLV::main();}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4052kb
input:
1 4 1 2 1 2 1111 1111 1111 1111
output:
51
result:
ok single line: '51'
Test #2:
score: 0
Accepted
time: 583ms
memory: 4240kb
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