제출 #1303372

#제출 시각아이디문제언어결과실행 시간메모리
1303372tdoxsanhPalindromic Partitions (CEOI17_palindromic)C++20
100 / 100
121 ms35564 KiB
#include <bits/stdc++.h> //#include <windows.h> //#include <conio.h> #define N 1001001 #define M #define CODE "SIXCUP" #define MOD #define MOD1 1000000007 #define MOD2 998244353 #define F first #define S second #define pb push_back #define eb emplace_back #define is insert #define mkp make_pair typedef int ui; typedef long long ul; typedef long double ud; typedef std::pair<int,int> pii; typedef std::pair<long long,long long> pll; using namespace std; constexpr int iinf=(int)1e9+7; constexpr long long linf=(long long)1e18+7; /// -- GLOBAL VAR -- ul T,ans; string s; pll hs[N],base={263,271},pw[N]; /// -- UTILS -- template<class A,class B> A maximize(A &a,const B &b) { return a=a>b?a:b; } template<class A,class B> A minimize(A &a,const B &b) { return a=a<b?a:b; } #ifndef MOD template<class A,class B> void add(A &a, const B &b) { a+=b; if(a>=MOD) a-=MOD; } template<class A,class B> void sub(A &a,const B &b) { a-=b; if(a<0) a+=MOD; } #endif /// -- DATA STRUCTURES -- /// -- SOLVERS -- void powCalc() { pw[0].F=1; pw[0].S=1; for(ui i=1;i<N;i++) { pw[i].F=(pw[i-1].F*base.F)%MOD1; pw[i].S=(pw[i-1].S*base.S)%MOD2; } } void hashing() { for(ui i=1;i<(ui)s.size();i++) { hs[i].F=(1LL*hs[i-1].F*base.F+(ui)s[i])%MOD1; hs[i].S=(1LL*hs[i-1].S*base.S+(ui)s[i])%MOD2; } } pii getHash(ui l,ui r) { pii has; has.F=(hs[r].F-hs[l-1].F*pw[r-l+1].F+1LL*MOD1*MOD1)%MOD1; has.S=(hs[r].S-hs[l-1].S*pw[r-l+1].S+1LL*MOD2*MOD2)%MOD2; return has; } /// -- CHECKER -- bool AC=true; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void getRand(ui &n,ui l,ui r) { uniform_int_distribution<ui> dist(l,r); n=dist(rng); } void printInput() { } void comparator(ui test) { vector<ui> ansA,ansB; cerr<<"Test case #"<<test<<": "; for(ui i=0;i<(ui)ansA.size();i++) { if(ansA[i]!=ansB[i]) { cerr<<"Wrong answer\n"; printInput(); cerr<<"Test "<<i<<": Expected: '"<<ansA[i]<<"', found: '"<<ansB[i]<<"'\n"; AC=false; return ; } } cerr<<"Accepted\n"; } /// -- INPUT -- void read() { cin>>T; } /// -- MAIN SOLVER -- void mainSolve() { powCalc(); while(T--) { bool ok=true; ans=0; cin>>s; s=" "+s; hashing(); for(ui l=1,r=(ui)s.size()-1,pre1=1,pre2=(ui)s.size()-1;l<r;l++,r--) { pii hashL,hashR; hashL=getHash(pre1,l); hashR=getHash(r,pre2); if(hashL.F==hashR.F && hashL.S==hashR.S) { if(l==r-1) ok=false; pre1=l+1; pre2=r-1; ans+=2; } } cout<<ans+ok<<"\n"; } } /// -- MAIN -- int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); #ifdef CODE if(fopen(CODE".INP","r")) { freopen(CODE".INP","r",stdin); freopen(CODE".OUT","w",stdout); } #endif // CODE #define __FILE_CHECK__ #ifdef __FILE_CHECK__ if(fopen("inp.txt","r")) { freopen("inp.txt","r",stdin); freopen("out.txt","w",stdout); freopen("ans.txt","w",stderr); } #endif // __FILE_CHECK__ read(); mainSolve(); return 0; } /** -- DRAFT -- -- END -- **/

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

palindromic.cpp: In function 'int32_t main()':
palindromic.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(CODE".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:147:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  147 |         freopen(CODE".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:154:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |        freopen("inp.txt","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:155:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  155 |        freopen("out.txt","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:156:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  156 |        freopen("ans.txt","w",stderr);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...