# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
256608 | 2020-08-03T00:48:05 Z | Marlov | Mate (COCI18_mate) | C++14 | 2000 ms | 29760 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]; vector<int> arr[26][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<s.length();i++){ for(int j=i+1;j<s.length();j++){ int fc=s[i]-'a'; int sc=s[j]-'a'; arr[fc][sc].push_back(i); } } int tl; char c1,c2; int fv,sv; for(int i=0;i<Q;i++){ cin>>tl>>c1>>c2; int result=0; fv=c1-'a'; sv=c2-'a'; for(int j=0;j<arr[fv][sv].size();j++){ if(arr[fv][sv][j]+2>=tl){ result+=pc[arr[fv][sv][j]][tl-2]; //cout<<arr[fv][sv][j]<<" did "<<pc[arr[fv][sv][j]][tl-2]<<'\n'; result%=MOD; } } cout<<result<<'\n'; } return 0; } /* 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 14464 KB | Output is correct |
2 | Correct | 14 ms | 14336 KB | Output is correct |
3 | Correct | 14 ms | 14464 KB | Output is correct |
4 | Correct | 17 ms | 14592 KB | Output is correct |
5 | Correct | 45 ms | 16120 KB | Output is correct |
6 | Correct | 52 ms | 16376 KB | Output is correct |
7 | Correct | 52 ms | 15984 KB | Output is correct |
8 | Correct | 39 ms | 15736 KB | Output is correct |
9 | Execution timed out | 2076 ms | 29760 KB | Time limit exceeded |
10 | Execution timed out | 2060 ms | 29664 KB | Time limit exceeded |