Submission #297566

# Submission time Handle Problem Language Result Execution time Memory
297566 2020-09-11T15:58:30 Z Hehehe Mate (COCI18_mate) C++14
0 / 100
3 ms 512 KB
#include<bits/stdc++.h> //:3
#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];
char l1,l2;
int n,i,j,x,y,q,lg;
int main (){

    string s;
    scanf("%s",s);
    n = s.size();
    s = '.' + s;

    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];
            if (c[i][j] >= MOD)
                c[i][j] -= MOD;
        }}


    for (i=1;i<=n;i++)
        for (j=i+1;j<=n;j++)
            a[i][v[j]]++;


    for (lg=2;lg<=n;lg++){
        for (i=lg-1;i<=n;i++){
            x = v[i];
            for (y=1;y<=26;y++){
                dp[lg][x][y] = dp[lg][x][y]+1LL*a[i][y]*c[i-1][lg-2]%MOD;
                if (dp[lg][x][y] >= MOD)
                    dp[lg][x][y] -= MOD;
            }}}


    scanf("%d",&q);
    for (;q--;){
        scanf("%d %c %c",&lg,&l1,&l2);
        printf("%d\n",dp[lg][l1-'a'+1][l2-'a'+1]);
    }


    return 0;
}

Compilation message

mate.cpp: In function 'int main()':
mate.cpp:14:13: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'std::string' {aka 'std::__cxx11::basic_string<char>'} [-Wformat=]
   14 |     scanf("%s",s);
      |            ~^
      |             |
      |             char*
mate.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~
mate.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
mate.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%d %c %c",&lg,&l1,&l2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11
2 Runtime error 2 ms 384 KB Execution killed with signal 11
3 Runtime error 3 ms 384 KB Execution killed with signal 11
4 Runtime error 2 ms 512 KB Execution killed with signal 11
5 Runtime error 2 ms 384 KB Execution killed with signal 11
6 Runtime error 2 ms 384 KB Execution killed with signal 11
7 Runtime error 2 ms 384 KB Execution killed with signal 11
8 Runtime error 2 ms 384 KB Execution killed with signal 11
9 Runtime error 2 ms 384 KB Execution killed with signal 11
10 Runtime error 2 ms 384 KB Execution killed with signal 11