Submission #1777370


Source Code Expand

#include<bits/stdc++.h>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;

#define xx first
#define yy second

template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
#define I inline
#define mset(a,b) memset(a,b,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define fd0(i,n) for(int i=(n)-1;~i;i--)
#define fd1(i,n) for(int i=n;i;i--)
#define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define foe(i,x)for(__typeof(x.end())i=x.begin();i!=x.end();++i)

struct Cg{I char operator()(){return getchar();}};
struct Cp{I void operator()(char x){putchar(x);}};
#define OP operator
#define RT return *this;
#define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\
if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x
#define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x;
I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int&x)
{RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char&x)
{for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char*x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS
(t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf&x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf&x){RX;RL;RT}I OP llf()
{llf x;TR}I Fr&OP,(uint&x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull&x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in;
#define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\
x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5);
#define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT}
I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP()
(ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char*x){while(*x)P(*x++);RT}
I Fw&OP()(const char*x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out;

const int N=1000007;

char s[N],t[N];
int n,a[N],b[N];

int main()
{
	in,n,s+1,t+1;
	bool equ=1;
	fo1(i,n)equ&=s[i]==t[i];
	if(equ)return puts("0"),0;
	int c=0,cur=n;
	fd1(i,n)if(t[i]!=t[i-1])
	{
		b[c]=i;
		repl(cur,i);
		for(;cur&&t[i]!=s[cur];cur--);
		if(!cur)return puts("-1"),0;
		a[c++]=cur--;
	}
	std::reverse(a,a+c);
	std::reverse(b,b+c);
	int ans=0;
	fo0(i,c)
	{
		int j=i;
		for(;j<c&&a[j]-b[i]<j-i;j++);
		repr(ans,j-i);
	}
	out,ans+1,'\n';
}

Submission Info

Submission Time
Task F - Shik and Copying String
User mcfx
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3713 Byte
Status TLE
Exec Time 2103 ms
Memory 9984 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1500
Status
AC × 4
AC × 54
TLE × 9
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 2 ms 2304 KB
001.txt AC 2 ms 2304 KB
002.txt AC 2 ms 4352 KB
003.txt AC 2 ms 2304 KB
004.txt AC 2 ms 4352 KB
005.txt AC 2 ms 4352 KB
006.txt AC 2 ms 4352 KB
007.txt AC 2 ms 4352 KB
008.txt AC 2 ms 4352 KB
009.txt AC 2 ms 4352 KB
010.txt AC 2 ms 4352 KB
011.txt AC 2 ms 4352 KB
012.txt AC 2 ms 4352 KB
013.txt AC 2 ms 4352 KB
014.txt AC 2 ms 4352 KB
015.txt AC 2 ms 4352 KB
016.txt AC 2 ms 4352 KB
017.txt AC 2 ms 4352 KB
018.txt AC 2 ms 4352 KB
019.txt AC 2 ms 4352 KB
020.txt AC 2 ms 4352 KB
021.txt AC 2 ms 4352 KB
022.txt AC 2 ms 4352 KB
023.txt AC 2 ms 4352 KB
024.txt AC 2 ms 4352 KB
025.txt AC 19 ms 3840 KB
026.txt TLE 2103 ms 9984 KB
027.txt TLE 2103 ms 9856 KB
028.txt AC 37 ms 9984 KB
029.txt AC 53 ms 9984 KB
030.txt AC 23 ms 8448 KB
031.txt AC 23 ms 8448 KB
032.txt AC 23 ms 8448 KB
033.txt AC 23 ms 8448 KB
034.txt AC 23 ms 8448 KB
035.txt AC 23 ms 8320 KB
036.txt AC 23 ms 8320 KB
037.txt AC 23 ms 8320 KB
038.txt AC 23 ms 8192 KB
039.txt AC 23 ms 8192 KB
040.txt AC 30 ms 9984 KB
041.txt AC 35 ms 9984 KB
042.txt AC 91 ms 9984 KB
043.txt AC 147 ms 9984 KB
044.txt AC 580 ms 9984 KB
045.txt AC 1098 ms 9984 KB
046.txt TLE 2103 ms 9984 KB
047.txt TLE 2103 ms 9984 KB
048.txt TLE 2103 ms 9984 KB
049.txt TLE 2103 ms 9984 KB
050.txt AC 23 ms 9984 KB
051.txt AC 22 ms 9984 KB
052.txt AC 22 ms 9984 KB
053.txt AC 171 ms 9856 KB
054.txt AC 308 ms 9984 KB
055.txt AC 1314 ms 9984 KB
056.txt TLE 2103 ms 9856 KB
057.txt TLE 2103 ms 9856 KB
058.txt TLE 2103 ms 9856 KB
example0.txt AC 2 ms 4352 KB
example1.txt AC 2 ms 2304 KB
example2.txt AC 2 ms 4352 KB
example3.txt AC 2 ms 2304 KB