Submission #1005521
Source Code Expand
#define DEB #include<bits/stdc++.h> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; } template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; } typedef long long int lint; typedef pair<int,int> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } const int INF=5e8; int n; string s,t; pi ps[1000005]; void ng(){ puts("-1"); exit(0); } int main(){ cin>>n>>s>>t; if(s==t){ puts("0"); return 0; } int q=n-1; int m=0; for(int i=n-1;i>=0;--i){ int j=i; while(j>=0 && t[j]==t[i]) --j; int p=i; q=min(j+1,q); while(q>=0 && s[q]!=t[p]) --q; if(q<0) ng(); ps[m++]=mp(q,p); if(p<q) ng(); i=j+1; } ps[m++]=mp(INF,0); sort(ps,ps+m); int lb=-1,ub=n+1; while(ub-lb>1){ int md=(lb+ub)>>1; bool fail=false; REP(i,m-1){ int trg=ps[min(m-1,i+md)].fr-md; if(trg<ps[i].sc) fail=true; } if(fail) lb=md; else ub=md; } printf("%d\n",ub); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Shik and Copying String |
User | hogloid |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 1715 Byte |
Status | AC |
Exec Time | 215 ms |
Memory | 10120 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 3 ms | 256 KB |
001.txt | AC | 3 ms | 256 KB |
002.txt | AC | 3 ms | 256 KB |
003.txt | AC | 3 ms | 256 KB |
004.txt | AC | 3 ms | 256 KB |
005.txt | AC | 3 ms | 256 KB |
006.txt | AC | 3 ms | 256 KB |
007.txt | AC | 3 ms | 256 KB |
008.txt | AC | 3 ms | 256 KB |
009.txt | AC | 3 ms | 256 KB |
010.txt | AC | 3 ms | 256 KB |
011.txt | AC | 3 ms | 256 KB |
012.txt | AC | 3 ms | 256 KB |
013.txt | AC | 3 ms | 256 KB |
014.txt | AC | 3 ms | 256 KB |
015.txt | AC | 3 ms | 256 KB |
016.txt | AC | 3 ms | 256 KB |
017.txt | AC | 3 ms | 256 KB |
018.txt | AC | 3 ms | 256 KB |
019.txt | AC | 3 ms | 256 KB |
020.txt | AC | 3 ms | 256 KB |
021.txt | AC | 3 ms | 256 KB |
022.txt | AC | 3 ms | 256 KB |
023.txt | AC | 3 ms | 256 KB |
024.txt | AC | 3 ms | 256 KB |
025.txt | AC | 106 ms | 2692 KB |
026.txt | AC | 214 ms | 10120 KB |
027.txt | AC | 140 ms | 6280 KB |
028.txt | AC | 166 ms | 7304 KB |
029.txt | AC | 166 ms | 7304 KB |
030.txt | AC | 85 ms | 3336 KB |
031.txt | AC | 85 ms | 3208 KB |
032.txt | AC | 85 ms | 3208 KB |
033.txt | AC | 85 ms | 3208 KB |
034.txt | AC | 84 ms | 3208 KB |
035.txt | AC | 84 ms | 3080 KB |
036.txt | AC | 82 ms | 3080 KB |
037.txt | AC | 81 ms | 2952 KB |
038.txt | AC | 80 ms | 2952 KB |
039.txt | AC | 77 ms | 2824 KB |
040.txt | AC | 147 ms | 6280 KB |
041.txt | AC | 175 ms | 7944 KB |
042.txt | AC | 206 ms | 9736 KB |
043.txt | AC | 210 ms | 9864 KB |
044.txt | AC | 214 ms | 10120 KB |
045.txt | AC | 214 ms | 10120 KB |
046.txt | AC | 215 ms | 10120 KB |
047.txt | AC | 215 ms | 10120 KB |
048.txt | AC | 215 ms | 10120 KB |
049.txt | AC | 214 ms | 10120 KB |
050.txt | AC | 84 ms | 10120 KB |
051.txt | AC | 84 ms | 10120 KB |
052.txt | AC | 75 ms | 6280 KB |
053.txt | AC | 143 ms | 6280 KB |
054.txt | AC | 143 ms | 6280 KB |
055.txt | AC | 143 ms | 6280 KB |
056.txt | AC | 143 ms | 6280 KB |
057.txt | AC | 142 ms | 6280 KB |
058.txt | AC | 143 ms | 6280 KB |
example0.txt | AC | 3 ms | 256 KB |
example1.txt | AC | 3 ms | 256 KB |
example2.txt | AC | 3 ms | 256 KB |
example3.txt | AC | 3 ms | 256 KB |