# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
257024 | 2020-08-03T14:09:37 Z | Marlov | Mate (COCI18_mate) | C++14 | 2000 ms | 19640 KB |
/* Code by @marlov */ #include <iostream> #include <fstream> #include <string> #include <sstream> #include <vector> #include <string> #include <cmath> #include <algorithm> #include <iomanip> #include <utility> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <stack> #include <queue> #include <iterator> using namespace std; typedef long long ll; typedef pair<int,int> pi; #define maxV 2005 #define MOD 1000000007 string s; int Q; int pc[maxV][maxV]; int dp[maxV][26]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>s; cin>>Q; 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]; } } } int tl; char fc,sc; for(int i=0;i<Q;i++){ int result=0; cin>>tl>>fc>>sc; for(int i=tl-2;i<s.length()-1;i++){ if(s[i]==fc){ result+=pc[i][tl-2]*(dp[i+1][sc-'a']); result%=MOD; } } cout<<result<<'\n'; } return 0; } /* malimateodmameitate 3 10 ot 7 aa 3 me */ /* stuff you should look for * int overflow, array bounds * special cases (n=1,n=0?) * do smth instead of nothing and stay organized */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 14336 KB | Output is correct |
2 | Incorrect | 14 ms | 14208 KB | Output isn't correct |
3 | Correct | 15 ms | 14208 KB | Output is correct |
4 | Incorrect | 17 ms | 14336 KB | Output isn't correct |
5 | Incorrect | 56 ms | 15096 KB | Output isn't correct |
6 | Incorrect | 62 ms | 15224 KB | Output isn't correct |
7 | Incorrect | 52 ms | 15096 KB | Output isn't correct |
8 | Incorrect | 46 ms | 14968 KB | Output isn't correct |
9 | Incorrect | 1795 ms | 19376 KB | Output isn't correct |
10 | Execution timed out | 2021 ms | 19640 KB | Time limit exceeded |