# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257758 | 2020-08-04T17:45:09 Z | updown1 | Mate (COCI18_mate) | C++17 | 2000 ms | 29592 KB |
/* Code by @marlov */ #include <bits/stdc++.h> using namespace std; #define maxV 2005 #define MOD 1000000007 string s; int Q; long long pc[maxV][maxV]; long long dp[maxV][26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>s; cin>>Q; //precomute pc[n][m] which is the nCm for(int i=0;i<maxV;i++){ pc[i][0]=1; for(int j=1;j<i;j++){ pc[i][j]=pc[i-1][j]+pc[i-1][j-1]; pc[i][j]%=MOD; } pc[i][i]=1; } for(int i=0;i<26;i++){ for(int j=s.length()-1;j>=0;j--){ if(s[j]=='a'+i){ dp[j][i]++; } if(j<s.length()-1){ dp[j][i]+=dp[j+1][i]; } } } long long tl; char fc,sc; for(int i=0;i<Q;i++){ long long result=0; cin>>tl>>fc>>sc; for(int j=tl-2;j<s.length()-1;j++){ if(s[j]==fc){ result= (result + pc[j][tl-2]*(dp[j+1][sc-'a']))%MOD; } } cout<<result<<'\n'; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 23288 KB | Output is correct |
2 | Correct | 18 ms | 23296 KB | Output is correct |
3 | Correct | 21 ms | 23296 KB | Output is correct |
4 | Correct | 23 ms | 23288 KB | Output is correct |
5 | Correct | 62 ms | 24188 KB | Output is correct |
6 | Correct | 75 ms | 24312 KB | Output is correct |
7 | Correct | 57 ms | 24184 KB | Output is correct |
8 | Correct | 51 ms | 24056 KB | Output is correct |
9 | Execution timed out | 2072 ms | 29176 KB | Time limit exceeded |
10 | Execution timed out | 2067 ms | 29592 KB | Time limit exceeded |