Submission #256609

#TimeUsernameProblemLanguageResultExecution timeMemory
256609MarlovMate (COCI18_mate)C++14
80 / 100
2089 ms29428 KiB
/* 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=lower_bound(arr[fv][sv].begin(),arr[fv][sv].end(),tl-2)-arr[fv][sv].begin();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 (stderr)

mate.cpp: In function 'int main()':
mate.cpp:45:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.length();i++){
              ~^~~~~~~~~~~
mate.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=i+1;j<s.length();j++){
                 ~^~~~~~~~~~~
mate.cpp:61:90: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=lower_bound(arr[fv][sv].begin(),arr[fv][sv].end(),tl-2)-arr[fv][sv].begin();j<arr[fv][sv].size();j++){
                                                                                         ~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...