답안 #297531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297531 2020-09-11T15:45:09 Z Hehehe Mate (COCI18_mate) C++14
0 / 100
500 ms 34556 KB
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 2e3 + 11;
const int X = 1e6;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

//ifstream in(".in");
//ofstream out(".out");

int n, m, a[N], c[N][N], dp[N][30][30], M[N][N];
string s;

void solve(){

    cin >> s;
    n = sz(s);
    s = '.' + s;

    for(int i = 1; i <= n; i++){
        a[i] = s[i] - 'a' + 1;
    }

    c[0][0] = 1; c[0][1] = 1; c[1][1] = 1;

    for(int i = 2; i <= n; i++){
        c[i][0] = 1;
        for(int j = 1; j <= i; j++){
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
            if(c[i][j] >= mod)c[i][j] -= mod;
            //cout << c[i][j] << ' ';
        }//cout << '\n';
    }

    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            M[i][a[j]]++;
        }
    }

    for(int len = 2; len <= n; len++){
        for(int i = 1; i <= n; i++){
            int x = a[i];
            for(int y = 1; y <= 26; y++){
                dp[len][x][y] += M[i][y]*c[i - 1][len - 2];
                if(dp[len][x][y] >= mod)dp[len][x][y] -= mod;
            }
        }
    }

    int q;
    cin >> q;
    while(q--){
        int x; char l, r;
        cin >> x >> l >> r;
        cout << dp[x][l - 'a' + 1][r - 'a' + 1] << '\n';
    }
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //cout << setprecision(6) << fixed;

    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1024 KB Output isn't correct
2 Incorrect 4 ms 896 KB Output isn't correct
3 Incorrect 5 ms 896 KB Output isn't correct
4 Incorrect 8 ms 1024 KB Output isn't correct
5 Incorrect 35 ms 3704 KB Output isn't correct
6 Incorrect 38 ms 3712 KB Output isn't correct
7 Incorrect 33 ms 3584 KB Output isn't correct
8 Incorrect 28 ms 3456 KB Output isn't correct
9 Incorrect 500 ms 34552 KB Output isn't correct
10 Incorrect 492 ms 34556 KB Output isn't correct