# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
257802 | 2020-08-04T20:18:37 Z | Marlov | Mate (COCI18_mate) | C++14 | 242 ms | 26488 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<long long,long long> pi; #define maxV 2005 #define MOD 1000000007 string s; long long Q; long long pc[maxV][maxV]; long long dp[maxV][26]; vector<int> cnts[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(long long i=0;i<maxV;i++){ pc[i][0]=1; for(long long 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<s.length();i++){ cnts[s[i]-'a'].push_back(i); } for(long long i=0;i<26;i++){ for(long long 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(long long i=0;i<Q;i++){ long long result=0; cin>>tl>>fc>>sc; for(long long j=0;j<cnts[fc-'a'].size();j++){ if(cnts[fc-'a'][j]>=tl-2&&cnts[fc-'a'][j]<s.length()-1){ result+=pc[j][tl-2]*(dp[j+1][sc-'a']); result%=MOD; } } cout<<result<<'\n'; } return 0; } /* malimateodmameitate 3 10 ot 7 aa 3 me */ /* stuff you should look for * long long overflow, array bounds * special cases (n=1,n=0?) * do smth instead of nothing and stay organized */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 18 ms | 23288 KB | Output isn't correct |
2 | Incorrect | 25 ms | 23296 KB | Output isn't correct |
3 | Incorrect | 17 ms | 23296 KB | Output isn't correct |
4 | Incorrect | 20 ms | 23424 KB | Output isn't correct |
5 | Incorrect | 44 ms | 24312 KB | Output isn't correct |
6 | Incorrect | 45 ms | 24440 KB | Output isn't correct |
7 | Incorrect | 42 ms | 24056 KB | Output isn't correct |
8 | Incorrect | 35 ms | 24056 KB | Output isn't correct |
9 | Incorrect | 242 ms | 26464 KB | Output isn't correct |
10 | Incorrect | 232 ms | 26488 KB | Output isn't correct |