제출 #122376

#제출 시각아이디문제언어결과실행 시간메모리
122376_7_7_Palindromic Partitions (CEOI17_palindromic)C++14
100 / 100
239 ms17388 KiB
#include <bits/stdc++.h> //#define int long long //#pragma GCC optimize("Ofast") //#pragma comment(linker, "/stack:200000000") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4") #define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout); #define forev(i, b, a) for(int i = (b); i >= (a); --i) #define forn(i, a, b) for(int i = (a); i <= (b); ++i) #define sz(s) (int)s.size() #define all(x) x.bg, x.en #define pb push_back #define ppb pop_back #define mp make_pair #define rbg rbegin() #define bg begin() #define en end() #define s second #define f first using namespace std; typedef pair < long long, long long > pll; typedef pair < int, int > pii; typedef unsigned long long ull; typedef vector < pii > vpii; typedef vector < int > vi; typedef long double ldb; typedef long long ll; typedef double db; const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 265; const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9); const int inf = 1e9, N = 1e6 + 11, mod = 1e9 + 7; const db eps = 1e-12, pi = 3.14159265359; const ll INF = 1e18; int t, n; pii pw[N], h[N]; char s[N]; pii get (int i, int j) { if (!i) return h[j]; return mp((Mod.f + h[j].f - h[i - 1].f * 1ll * pw[j - i + 1].f % Mod.f) % Mod.f, (Mod.s + h[j].s - h[i - 1].s * 1ll * pw[j - i + 1].s % Mod.s) % Mod.s); } void precalc () { pw[0] = mp(1, 1); forn (i, 1, N - 1) pw[i] = mp(pw[i - 1].f * 1ll * base.f % Mod.f, pw[i - 1].s * 1ll * base.s % Mod.s); } main () { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); precalc(); scanf("%d", &t); while (t--) { scanf("\n%s", s); h[0] = mp(s[0], s[0]); n = strlen(s); forn (i, 1, n - 1) h[i] = mp((h[i - 1].f * 1ll * base.f % Mod.f + s[i]) % Mod.f, (h[i - 1].s * 1ll * base.s % Mod.s + s[i]) % Mod.s); int i = 0, j = n - 1, ans = 0; while (i <= j) { int len = 1; while (get(i, i + len - 1) != get(j - len + 1, j)) { ++len; /* cerr << len << endl; cerr << get(i, i + len - 1).f << ' ' << get(j, j - len + 1).f << endl; cerr << get(i, i + len - 1).s << ' ' << get(j, j - len + 1).s << endl; cerr << endl; if (len == 2) break; */ } if (i + len - 1 == j) ans++; else ans += 2; i += len; j -= len; } printf("%d\n", ans); } return 0; }

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

palindromic.cpp:65:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
palindromic.cpp: In function 'int main()':
palindromic.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &t);
  ~~~~~^~~~~~~~~~
palindromic.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("\n%s", s);
   ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...