답안 #223254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223254 2020-04-15T06:19:02 Z cheeheng Lampice (COCI19_lampice) C++14
0 / 110
5000 ms 4096 KB
#include <bits/stdc++.h>
using namespace std;

char S[50005];

vector<int> AdjList[50005];

const long long MOD = 2147483647LL;

long long pow26[50005];

int main(){
    int N;
    scanf("%d", &N);

    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(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

lampice.cpp: In function 'int main()':
lampice.cpp:31:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if(a == i && b == i+1 || b == i && a == i+1){
            ~~~~~~~^~~~~~~~~~~
lampice.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
lampice.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c", &S[i]);
         ~~~~~^~~~~~~~~~~~~~
lampice.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5069 ms 3840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 4096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -