답안 #238571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238571 2020-06-11T22:08:45 Z vankata Trener (COCI20_trener) C++14
0 / 110
20 ms 1024 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2048;
const int MOD = (int)(1e9+7);

map< pair<int,int> ,long long >mp;

long long n,k;

bool cmp(string a,string b)
{
    for(size_t i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])return false;
    }return true;
}

int base1 = 29 ;
int base2 = 31 ;
int mod1=1e5+3;
int mod2=100019;

pair<int,int> hsh(string s)
{
    int i,j;
    int h1=0,h2=0;
    for(i=0;i<s.size();i++)
    {
        h1*=base1;
        h2*=base2;
        h1+=(s[i]-'a'+1);
        h2+=(s[i]-'a'+1);
        h1%=mod1;
        h2%=mod2;
    }
    return {h1,h2};
}

void read()
{
    int i,j,l;
    long long ans = 0;
    cin>>n>>k;
    string s,t,q;
    int lm=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<k;j++)
        {
            cin>>s;

            if(!i){mp[hsh(s)]++;continue;}

            t="";
            q="";
            t=s.substr(0,s.size()-1);
            q=s.substr(1);

            mp[hsh(s)]+=mp[hsh(q)];
            if(!cmp(q,t))mp[hsh(s)]+=mp[hsh(t)];
            mp[hsh(s)]%=MOD;
            if(i==n-1)
            {
                ans+=mp[hsh(s)];
                ans%=MOD;
            }
        }
    }
    if(n==1)
    {
        cout<<k<<endl;
        return ;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    read();
    return 0;
}

Compilation message

trener.cpp: In function 'std::pair<int, int> hsh(std::__cxx11::string)':
trener.cpp:28:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<s.size();i++)
             ~^~~~~~~~~
trener.cpp:26:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j;
           ^
trener.cpp: In function 'void read()':
trener.cpp:42:13: warning: unused variable 'l' [-Wunused-variable]
     int i,j,l;
             ^
trener.cpp:46:9: warning: unused variable 'lm' [-Wunused-variable]
     int lm=0;
         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1024 KB Output is correct
2 Correct 19 ms 1024 KB Output is correct
3 Correct 20 ms 1024 KB Output is correct
4 Incorrect 12 ms 512 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 5 ms 384 KB Output isn't correct