Submission #1071498


Source Code Expand

#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
//const int mo=0;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

int n;
char s[1111111],t[1111111];
int lasp[555];
int a[1111111];
bool vis[1111111];
int cnt=0;

int pos[1111111];
int lis[1111111];
int nedpos[1111111];
bool check(int t){
	lis[cnt+1]=n+1;
	rep(i,1,cnt+1){
		int tar=i+t;
		if(tar>cnt+1)tar=lis[cnt+1]+(tar-(cnt+1));
		else tar=lis[tar];
		tar-=t;
		pos[lis[i]]=tar;
	}
	rep(i,1,cnt+1)if(nedpos[lis[i]]>pos[lis[i]])return 0;
	return 1;
}
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif
	gn(n);
	gs(s+1);
	gs(t+1);

	int cur=n;
	per(i,1,n+1){
		cur=min(cur,i);
		while(cur>=1 && s[cur]!=t[i]){
			cur--;
		}
		if(cur==0){
			printf("-1\n");
			return 0;
		}
		a[i]=cur;
	}
	rep(i,1,n+1){
		vis[a[i]]=1;
		if(i==n || a[i]!=a[i+1]){
			nedpos[a[i]]=i;
		}
	}
	rep(i,1,n+1)if(vis[i])lis[++cnt]=i;

	int l=0,r=n+1;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid))r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",l);
#ifdef JCVB
	debug("time: %d\n",int(clock()-_time_jc));
#endif
	return 0;
}


Submission Info

Submission Time
Task F - Shik and Copying String
User jcvb
Language C++14 (GCC 5.4.1)
Score 1500
Code Size 3980 Byte
Status AC
Exec Time 68 ms
Memory 18816 KB

Compile Error

./Main.cpp: In function ‘void gs(char*)’:
./Main.cpp:68:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 inline void gs(char *s){scanf("%s",s);}
                                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 4
AC × 63
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 67 ms 18816 KB
026.txt AC 51 ms 18816 KB
027.txt AC 34 ms 12416 KB
028.txt AC 66 ms 17408 KB
029.txt AC 65 ms 17408 KB
030.txt AC 68 ms 18560 KB
031.txt AC 67 ms 18432 KB
032.txt AC 63 ms 17920 KB
033.txt AC 62 ms 17664 KB
034.txt AC 56 ms 17152 KB
035.txt AC 55 ms 17024 KB
036.txt AC 49 ms 16640 KB
037.txt AC 47 ms 16256 KB
038.txt AC 44 ms 15744 KB
039.txt AC 39 ms 15104 KB
040.txt AC 60 ms 17152 KB
041.txt AC 63 ms 17792 KB
042.txt AC 66 ms 18560 KB
043.txt AC 66 ms 18688 KB
044.txt AC 67 ms 18816 KB
045.txt AC 67 ms 18816 KB
046.txt AC 68 ms 18816 KB
047.txt AC 65 ms 18816 KB
048.txt AC 65 ms 18816 KB
049.txt AC 65 ms 18816 KB
050.txt AC 15 ms 6144 KB
051.txt AC 16 ms 6144 KB
052.txt AC 13 ms 4224 KB
053.txt AC 52 ms 16896 KB
054.txt AC 52 ms 16896 KB
055.txt AC 49 ms 15360 KB
056.txt AC 49 ms 15104 KB
057.txt AC 48 ms 14720 KB
058.txt AC 48 ms 14720 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