Submission #169453

# Submission time Handle Problem Language Result Execution time Memory
169453 2019-12-20T12:17:05 Z Ruxandra985 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
52 ms 11144 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 , nr;
    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;
        nr = 0;
        while (l < r){
            prefix = ( prefix * ('z' - 'a') + (s[l] - 'a') )%MOD;
            suffix = ( ( s[r] - 'a' ) * prod + suffix )%MOD;
            prod = (prod * ('z' - 'a'))%MOD;
            nr++;
            if (prefix == suffix){
                sol+=2;
                prefix = 0;
                suffix = 0;
                prod = 1;
                nr = 0;
            }
            l++;
            r--;
        }
        if ( l == r || nr != 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 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 50 ms 11144 KB Output is correct
15 Correct 30 ms 6432 KB Output is correct
16 Correct 52 ms 10560 KB Output is correct
17 Correct 26 ms 6008 KB Output is correct