답안 #973903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973903 2024-05-02T12:38:45 Z vjudge1 Savez (COCI15_savez) C
48 / 120
1000 ms 11604 KB
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define N 500
#define TN 2000000
#define N_ (TN+N+100)
#define M (N*N*2)

char s[N_];
int p, n, z, at[N+1], hash[N_], BASE, MOD = 1000000007, head[N], nxt[M], vv[M], vis[N], dp[N];

unsigned rand_wide() { return 1llu * rand()*rand(); }
unsigned rand_wide2(unsigned l, unsigned r) { if (l==r)return l; return l+rand_wide()%(r-l); }

void link(int u, int v)
{
    static int i = 1;
    nxt[i] = head[u];
    vv[i] = v;
    head[u] = i++;
}

int power(int a,int b)
{
    if (!b)return 1;
    int r= power(a,b/2);
    if(b&1)return r*1ll*r%MOD*a%MOD;
    return r*1ll*r%MOD;
}

void dfs(int u)
{
    vis[u] = 1;
    for(int j = head[u]; j; j = nxt[j])
    {
        if (!vis[vv[j]]) dfs(vv[j]);
        if(dp[vv[j]]+1>dp[u])dp[u]=dp[vv[j]]+1;
    }
    if(dp[u]>z)z=dp[u];
}

int main()
{
    srand(time(0));
    BASE = rand_wide2(200, MOD-1);

    scanf("%d", &n);
    for (int len, i = 0; i < n; ++i)
        scanf("%s", s+(at[i]=p)), at[i+1]=p+=strlen(s+at[i])+1;

    for (int i=0;i<n;++i)
        for(int bp=1,j=at[i];s[j];++j,bp=bp*1ll*BASE%MOD)
            hash[j] = bp * 1ll * s[j]%MOD;

    for (int i=1;i<=at[n];++i)
        if(s[i]>0) hash[i]=(hash[i]+hash[i-1])%MOD;

    for (int i = 0; i < n; ++i)
    {
        int hash_i=hash[at[i+1]-2];
        for (int j = i + 1; j < n; ++j)
        {
            int leni=at[i+1]-at[i]-1,lenj=at[j+1]-at[j]-1;
            if(leni>lenj)continue;
            if(hash_i==hash[at[j]+leni-1]&&
                    hash_i*1ll*power(BASE,lenj-leni)%MOD==(hash[at[j+1]-2]+MOD-hash[at[j+1]-2-leni])%MOD)
                link(i, j);
        }
    }

    for (int i=0;i<n;++i)if(!vis[i])dfs(i);
    printf("%d",z+1);

}

Compilation message

savez.c: In function 'main':
savez.c:50:14: warning: unused variable 'len' [-Wunused-variable]
   50 |     for (int len, i = 0; i < n; ++i)
      |              ^~~
savez.c:49:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%d", &n);
      |     ^~~~~~~~~~~~~~~
savez.c:51:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%s", s+(at[i]=p)), at[i+1]=p+=strlen(s+at[i])+1;
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 5 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 11092 KB Output is correct
2 Correct 27 ms 10844 KB Output is correct
3 Correct 37 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 38 ms 10908 KB Output is correct
3 Correct 32 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1014 ms 11600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 11604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 293 ms 7696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 105 ms 7700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 7516 KB Time limit exceeded
2 Halted 0 ms 0 KB -