QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#772931 | #7006. Rikka with Subsequences | Crying | AC ✓ | 476ms | 40292kb | C++14 | 1.4kb | 2024-11-22 23:02:03 | 2024-11-22 23:02:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 210,mod = 1e9+7;
int addv(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
int subv(int x,int y){return (x>=y)?(x-y):(x-y+mod);}
void add(int& x,int y){x = addv(x,y);}
void sub(int& x,int y){x = subv(x,y);}
int qpow(int a,int n){
int res = 1; a%=mod;
while(n){
if(n&1)res = 1ll*res*a%mod;
n>>=1; a = 1ll*a*a%mod;
}
return res;
}
int qinv(int a){return qpow(a,mod-2);}
//
int T,n,a[N],e[N][N],f[N][N][N],g[N][N],h[N][N],ans;
void solve(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
memset(e,0,sizeof e);
for(int i=1;i<=n;i++){
string s; cin>>s; for(int j=1;j<=n;j++)e[i][j] = s[j-1]-'0';
}
memset(f,0,sizeof f);
memset(g,0,sizeof g);
ans = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)if(a[i] == a[j] && a[j] == a[k]){
f[i][j][k] = addv(g[j][k],1);
add(ans,f[i][j][k]);
}
memcpy(h,f[i],sizeof h);
for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)add(h[j][k],h[j][k-1]);
for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)add(h[j][k],h[j-1][k]);
for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)if(a[j] == a[k] && e[a[i]][a[j]]){
add(g[j][k],h[j-1][k-1]);
}
}
cout<<ans<<endl;
}
int main(){
cin>>T;
while(T--)solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 40292kb
input:
1 4 1 2 1 2 1111 1111 1111 1111
output:
51
result:
ok single line: '51'
Test #2:
score: 0
Accepted
time: 476ms
memory: 40240kb
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