# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
223283 | 2020-04-15T06:41:49 Z | cheeheng | Lampice (COCI19_lampice) | C++14 | 220 ms | 98424 KB |
#include <bits/stdc++.h> using namespace std; char S[50005]; vector<int> AdjList[50005]; const long long MOD = (1LL<<55)-3; long long pow26[50005]; long long dist[3005][3005]; int dist2[3005][3005]; int main(){ int N; scanf("%d", &N); assert(MOD%13 != 0); pow26[0] = 1; for(int i = 1; i <= N; i ++){ pow26[i] = pow26[i-1]*26%MOD; } for(int i = 1; i <= N; i ++){ scanf(" %c", &S[i]); } bool subtask2 = true; for(int i = 1; i < N; i ++){ int a, b; scanf("%d%d", &a, &b); AdjList[a].push_back(b); AdjList[b].push_back(a); if(a == i && b == i+1 || b == i && a == i+1){ }else{ subtask2 = false; } } if(N <= 3000){ int ans = 0; memset(dist, -1, sizeof(dist)); for(int i = 1; i <= N; i ++){ queue<int> q; q.push(i); dist[i][i] = S[i]-'a'; dist2[i][i] = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(int v: AdjList[u]){ if(dist[i][v] == -1){ dist[i][v] = (26*dist[i][u] + (S[v]-'a'))%MOD; dist2[i][v] = dist2[i][u]+1; q.push(v); } } } } for(int i = 1; i <= N; i ++){ for(int j = i; j <= N; j ++){ //printf("%d %d %lld %lld\n", i, j, dist[i][j], dist[j][i]); assert(dist[i][j] != -1); if(dist[i][j] == dist[j][i]){ ans = max(ans, 1+dist2[i][j]); } } } printf("%d", ans); return 0; } /*if(subtask2){ int ans = 0; for(int i = 1; i <= N; i ++){ long long forward1 = 0; long long backward1 = 0; for(int j = i; j <= N; j ++){ forward1 = (forward1*26+(S[j]-'0'))%MOD; backward1 += pow26[j-i]*(S[j]-'0'); backward1 %= MOD; if(forward1 == backward1){ ans = max(ans, j-i+1); } } } printf("%d", ans); return 0; }*/ return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 74104 KB | Output is correct |
2 | Correct | 59 ms | 77688 KB | Output is correct |
3 | Correct | 120 ms | 87160 KB | Output is correct |
4 | Correct | 220 ms | 98424 KB | Output is correct |
5 | Correct | 43 ms | 72188 KB | Output is correct |
6 | Correct | 42 ms | 72192 KB | Output is correct |
7 | Correct | 43 ms | 72188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 25 ms | 3576 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 31 ms | 3832 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 74104 KB | Output is correct |
2 | Correct | 59 ms | 77688 KB | Output is correct |
3 | Correct | 120 ms | 87160 KB | Output is correct |
4 | Correct | 220 ms | 98424 KB | Output is correct |
5 | Correct | 43 ms | 72188 KB | Output is correct |
6 | Correct | 42 ms | 72192 KB | Output is correct |
7 | Correct | 43 ms | 72188 KB | Output is correct |
8 | Incorrect | 25 ms | 3576 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |