답안 #257769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257769 2020-08-04T18:31:42 Z updown1 Mate (COCI18_mate) C++17
100 / 100
674 ms 30200 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> indices[26];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	//ofstream cout("Math.out");
	cin>>s;
	cin>>Q;
	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(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];
			}
		}
	}

	for (int j=0; j<s.length()-1; j++) {
        indices[s[j] - 'a'].push_back(j);
	}

	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=tl-2;j<s.length()-1;j++){
		for (int j: indices[fc-'a'])
			//if(s[j]==fc){
			if (j >= tl-2) {
				result+=pc[j][tl-2]*(dp[j+1][sc-'a']);
				result%=MOD;
			}
		//}
		cout<<result<<'\n';
	}
    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:53:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(j<s.length()-1){
       ~^~~~~~~~~~~~~
mate.cpp:59:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int j=0; j<s.length()-1; j++) {
                ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23424 KB Output is correct
2 Correct 20 ms 23296 KB Output is correct
3 Correct 21 ms 23296 KB Output is correct
4 Correct 32 ms 23416 KB Output is correct
5 Correct 46 ms 24952 KB Output is correct
6 Correct 52 ms 25036 KB Output is correct
7 Correct 41 ms 24828 KB Output is correct
8 Correct 41 ms 24568 KB Output is correct
9 Correct 662 ms 30072 KB Output is correct
10 Correct 674 ms 30200 KB Output is correct