답안 #143357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
143357 2019-08-13T18:51:03 Z nicolaalexandra Mate (COCI18_mate) C++14
0 / 100
2000 ms 27976 KB
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#define DIM 2010
#define MOD 1000000007
using namespace std;

//ifstream cin ("date.in");
//ofstream cout ("date.out");
int v[DIM],c[DIM][DIM],f[DIM],dp[DIM][30][30],a[DIM][30];
vector <int> pozx,pozy;
set <int> L;
char s[DIM],l1,l2;
int n,i,j,x,y,q,lg;
int main (){

    cin>>s+1;
    n = strlen(s+1);
    for (i=1;i<=n;i++)
        v[i] = s[i] - 'a' + 1;

    c[0][0] = c[1][0] = c[1][1] = 1;
    for (i=2;i<=n;i++){
        c[i][0] = 1;
        for (j=1;j<=i;j++)
            c[i][j] = (c[i-1][j] + c[i-1][j-1])%MOD;
    }

    /// a[i][x] - in cate moduri pot selecta s[i],j (am nevoie sa stiu pozitia primului)
    for (i=1;i<=n;i++)
        for (j=i+1;j<=n;j++)
            a[i][v[j]]++;

    /// dp[i][x][y] - cate siruri de lungime i care se termina cu xy pot obtine
    for (lg=2;lg<=n;lg++){
        for (i=lg;i<=n;i++){
            x = v[i];
            for (y=1;y<=26;y++)
                dp[lg][x][y] = (dp[lg][x][y]+a[i][y]*c[i-1][lg-2]%MOD)%MOD;
        }}

    /*for (x=1;x<=26;x++)
        for (y=1;y<=26;y++){
            if (x == 14 && y == 14)
                x = 14;
            pozy.clear(), pozx.clear(), L.clear();
            memset (f,0,sizeof f);
            for (i=1;i<=n;i++)
                if (v[i] == y)
                    pozy.push_back(i);
            int idx = 0;
            for (i=1;i<=n;i++){
                if (pozy[idx] == i){
                    for (j=0;j<pozx.size();j++){
                        L.insert(pozx[j]-1); /// pana unde pot selecta caractere
                        f[pozx[j]-1]++;
                    }
                    if (idx == pozy.size()-1)
                        break;
                    idx++;
                }
                if (v[i] == x)
                    pozx.push_back(i);
            }
            /// dp[i][x][y] - cate siruri de lungime i care se termina cu xy pot obtine
            for (i=2;i<=n;i++)
                for (set<int>:: iterator it=L.begin();it!=L.end();it++){
                    int lg = *it;
                    dp[i][x][y] = (dp[i][x][y] + c[lg][i-2]*f[lg]%MOD)%MOD;
                }}*/
    cin>>q;
    for (;q--;){
        cin>>lg>>l1>>l2;
        x = l1-'a'+1, y = l2-'a'+1;
        cout<<dp[lg][x][y]<<"\n";
    }



    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:18:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     cin>>s+1;
          ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 760 KB Output isn't correct
2 Incorrect 58 ms 760 KB Output isn't correct
3 Incorrect 68 ms 760 KB Output isn't correct
4 Incorrect 116 ms 904 KB Output isn't correct
5 Incorrect 413 ms 2808 KB Output isn't correct
6 Incorrect 470 ms 3064 KB Output isn't correct
7 Incorrect 360 ms 2808 KB Output isn't correct
8 Incorrect 323 ms 2680 KB Output isn't correct
9 Execution timed out 2048 ms 27760 KB Time limit exceeded
10 Execution timed out 2050 ms 27976 KB Time limit exceeded