Submission #1078057

# Submission time Handle Problem Language Result Execution time Memory
1078057 2024-08-27T12:06:15 Z khactrung1912 Lozinke (COCI17_lozinke) C++14
65 / 100
153 ms 3664 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int nx=2e4+5, mod=19122007;
 
#define ll long long
 
ll n, c[nx][12], sz[nx], res, p[nx], vl[nx];
string s;
map<ll, ll> mp;
 
int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    p[0]=1;
    for (int i=1; i<=10; i++) p[i]=(p[i-1]*30)%mod;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>s;
        sz[i]=s.size();
        for (int j=1; j<=sz[i]; j++) c[i][j]=s[j-1]-'a'+1;
    }
    for (int i=1; i<=n; i++)
    {
        set<ll> s;
        for (int j=1; j<=sz[i]; j++)
        {
            ll tmp=0;
            for (int k=j; k<=sz[i]; k++)
            {
                tmp=(tmp+c[i][k]*p[k-j])%mod;
                s.insert(tmp);
                if (j==1&&k==sz[i]) vl[i]=tmp;
            }
        }
        for (auto x:s) if (mp.find(x)!=mp.end()) res+=mp[x];
        mp[vl[i]]++;
    }
    mp.clear();
    for (int i=n; i>=1; i--)
    {
        set<ll> s;
        for (int j=1; j<=sz[i]; j++)
        {
            ll tmp=0;
            for (int k=j; k<=sz[i]; k++)
            {
                tmp=(tmp+c[i][k]*p[k-j])%mod;
                s.insert(tmp);
            }
        }
        for (auto x:s) if (mp.find(x)!=mp.end()) res+=mp[x];
        mp[vl[i]]++;
    }
    cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 11 ms 592 KB Output is correct
7 Incorrect 11 ms 860 KB Output isn't correct
8 Correct 12 ms 604 KB Output is correct
9 Correct 51 ms 1884 KB Output is correct
10 Incorrect 71 ms 1880 KB Output isn't correct
11 Incorrect 84 ms 2600 KB Output isn't correct
12 Incorrect 146 ms 2652 KB Output isn't correct
13 Correct 146 ms 3412 KB Output is correct
14 Incorrect 153 ms 3664 KB Output isn't correct
15 Incorrect 147 ms 3408 KB Output isn't correct
16 Correct 121 ms 2816 KB Output is correct
17 Correct 25 ms 2648 KB Output is correct
18 Correct 22 ms 2652 KB Output is correct
19 Incorrect 135 ms 3408 KB Output isn't correct
20 Correct 81 ms 2840 KB Output is correct