제출 #320682

#제출 시각아이디문제언어결과실행 시간메모리
320682phathnvPalindromic Partitions (CEOI17_palindromic)C++11
100 / 100
57 ms15076 KiB
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second using namespace std; typedef long long ll; typedef pair <int, int> ii; const int N = 1e6 + 1; const int base = 163; int t, n; char s[N]; ll pw[N]; void prepare(){ pw[0] = 1; for(int i = 1; i < N; i++) pw[i] = pw[i - 1] * base; } void readInput(){ scanf("%s", s + 1); n = strlen(s + 1); } void solve(){ int res = 0; int l = 1, r = n, len = 0; ll hashedL = 0, hashedR = 0; while (l < r){ hashedL = hashedL * base + s[l++]; hashedR = hashedR + s[r--] * pw[len++]; if (hashedL == hashedR){ hashedL = hashedR = 0; res += 2; len = 0; } } if (hashedL || l <= r) res++; printf("%d\n", res); } int main(){ scanf("%d", &t); prepare(); while (t--){ readInput(); solve(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

palindromic.cpp: In function 'void readInput()':
palindromic.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%s", s + 1);
      |     ~~~~~^~~~~~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...