Submission #256609

# Submission time Handle Problem Language Result Execution time Memory
256609 2020-08-03T00:50:34 Z Marlov Mate (COCI18_mate) C++14
80 / 100
2000 ms 29428 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=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

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 time Memory Grader output
1 Correct 15 ms 14336 KB Output is correct
2 Correct 13 ms 14208 KB Output is correct
3 Correct 16 ms 14208 KB Output is correct
4 Correct 17 ms 14336 KB Output is correct
5 Correct 47 ms 15224 KB Output is correct
6 Correct 49 ms 15352 KB Output is correct
7 Correct 41 ms 15224 KB Output is correct
8 Correct 37 ms 15096 KB Output is correct
9 Execution timed out 2039 ms 29428 KB Time limit exceeded
10 Execution timed out 2089 ms 28828 KB Time limit exceeded