Submission #169450

# Submission time Handle Problem Language Result Execution time Memory
169450 2019-12-20T12:13:00 Z Ruxandra985 Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#define MOD 1000000007
#define DIM 1000010
using namespace std;
char s[DIM];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int t , n, l , r , sol;
    long long prod , prefix , suffix;
    fscanf (fin,"%d\n",&t);
    for (;t;t--){
        fgets (s+1 , 1000010 , fin);
        n = 0;
        while ('a' <= s[n+1] && s[n+1] <= 'z')
            n++;
        l = 1;
        r = n;
        prefix = suffix = 0;
        prod = 1;
        sol = 0;
        while (l < r){
            prefix = ( prefix * ('z' - 'a') + (s[l] - 'a') )%MOD;
            suffix = ( ( s[r] - 'a' ) * prod + suffix )%MOD;
            prod = (prod * ('z' - 'a'))%MOD;
            if (prefix == suffix){
                sol+=2;
                prefix = 0;
                suffix = 0;
                prod = 1;
            }
            l++;
            r--;
        }
        if ( l == r || prefix !=0 )
            sol++;
        fprintf (fout,"%d\n" , sol);
    }
    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d\n",&t);
     ~~~~~~~^~~~~~~~~~~~~~~
palindromic.cpp:14:15: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         fgets (s+1 , 1000010 , fin);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:936:0,
                 from /usr/include/c++/7/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:46,
                 from palindromic.cpp:1:
In function 'char* fgets(char*, int, FILE*)',
    inlined from 'int main()' at palindromic.cpp:14:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:261:58: warning: call to '__fgets_chk_warn' declared with attribute warning: fgets called with bigger size than length of destination buffer
  return __fgets_chk_warn (__s, __bos (__s), __n, __stream);
                                                          ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -