結果

問題 No.1005 BOT対策
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-03-08 10:06:53
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 6,783 bytes
コンパイル時間 2,707 ms
コンパイル使用メモリ 114,848 KB
実行使用メモリ 32,640 KB
最終ジャッジ日時 2024-11-06 20:15:13
合計ジャッジ時間 4,739 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
32,640 KB
testcase_01 AC 36 ms
25,904 KB
testcase_02 AC 36 ms
25,572 KB
testcase_03 AC 37 ms
25,392 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using static Rh;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		var t=sc.S;
		Rh rh=new Rh();
		var hs=new Hsa(s);
		var ht=t;
		int ans=0;
		for(int i = t.Length-1;i<s.Length;i++) {
			if(hs.Get(i-t.Length+1,i)==ht){
				ans++;
				i+=t.Length-1;
				if(t[0]==t[t.Length-1]){i--;}
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Rh{
	public static readonly int mod1=1073741783,mod2=1073741789;
	public static readonly int b1=1007,b2=1009+DateTime.Now.Millisecond;
	private static long[] r1,r2;
	private static int n;
	public Rh(){n=0;}
	public Rh(int n){
		Rh.n=n;
		r1=new long[n+1];
		r2=new long[n+1];
		r1[0]=r2[0]=1;
		for(int i = 1;i<=n;i++) {
			r1[i]=(r1[i-1]*b1)%mod1;
			r2[i]=(r2[i-1]*b2)%mod2;
		}
	}
	public class Hsa{
		private Hs[] hs;
		public int n;
		public Hsa(int[] a){
			n=a.Length;
			if(n>Rh.n){
				Rh.n=n;
				r1=new long[n+1];
				r2=new long[n+1];
				r1[0]=r2[0]=1;
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {
					r1[i]=(r1[i-1]*b1)%mod1;
					r2[i]=(r2[i-1]*b2)%mod2;
					hs[i]=hs[i-1]+a[i-1];
				}
			}
			else{
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {hs[i]=hs[i-1]+a[i-1];}
			}
		}
		public Hsa(string a){
			n=a.Length;
			if(n>Rh.n){
				Rh.n=n;
				r1=new long[n+1];
				r2=new long[n+1];
				r1[0]=r2[0]=1;
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {
					r1[i]=(r1[i-1]*b1)%mod1;
					r2[i]=(r2[i-1]*b2)%mod2;
					hs[i]=hs[i-1]+a[i-1];
				}
			}
			else{
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {hs[i]=hs[i-1]+a[i-1];}
			}
		}
		public static implicit operator Hsa(int[] a){return new Hsa(a);}
		public static implicit operator Hsa(string a){return new Hsa(a);}
		public Hs Get(int a,int b){return hs[b+1]-hs[a];}
		public int Bs(int a,int b){return Bs(a,b,n-Max(a,b));}
		public int Bs(int a,int b,int ub){
			int lb=-1,mid=0;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(Get(a,a+mid)!=Get(b,b+mid)){ub=mid;}
				else{lb=mid;}
			}
			return ub;
		}
		public int Bsp(Hsa a){return Bsp(0,a);}
		public int Bsp(int k,Hsa a){
			int lb=-1,mid=0,ub=Min(n-k,a.n);
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(Get(k,mid+k)!=a.Get(0,mid)){ub=mid;}
				else{lb=mid;}
			}
			return ub;
		}
		public int Bss(Hsa a){return Bss(n-1,a);}
		public int Bss(int k,Hsa a){
			int lb=0,mid=0,ub=Min(k+1,a.n)+1;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(Get(k+1-mid,k)!=a.Get(a.n-mid,a.n-1)){ub=mid;}
				else{lb=mid;}
			}
			return lb;
		}
	}
	public struct Hs{
		public long h1,h2;
		public int d;
		public Hs(int n){h1=h2=d=0;}
		public static implicit operator bool(Hs h){return h.d>0;}
		public static implicit operator Hs(string s){
			Hs h=new Hs(0);
			for(int i=0;i<s.Length;i++){h+=s[i];}
			return h;
		}
		public static implicit operator Hs(int[] s){
			Hs h=new Hs(0);
			for(int i=0;i<s.Length;i++){h+=s[i];}
			return h;
		}
		public static Hs operator+(Hs a,int c){
			a.h1=(a.h1*b1+c)%mod1;
			a.h2=(a.h2*b2+c)%mod2;
			a.d++;
			return a;
		}
		public static Hs operator+(Hs a,Hs p){
			a.h1=(a.h1*r1[p.d]+p.h1)%mod1;
			a.h2=(a.h2*r2[p.d]+p.h2)%mod2;
			a.d+=p.d;
			return a;
		}
		public static Hs operator-(Hs a,int c){
			a.d--;
			a.h1=(a.h1+mod1-(r1[a.d]*c%mod1))%mod1;
			a.h2=(a.h2+mod2-(r2[a.d]*c%mod2))%mod2;
			return a;
		}
		public static Hs operator-(Hs a,Hs p){
			a.d-=p.d;
			a.h1=(a.h1+mod1-(r1[a.d]*p.h1%mod1))%mod1;
			a.h2=(a.h2+mod2-(r2[a.d]*p.h2%mod2))%mod2;
			return a;
		}
		public static bool operator==(Hs a,Hs b){return a.h1==b.h1&&a.h2==b.h2&&a.d==b.d;}
		public static bool operator!=(Hs a,Hs b){return a.h1!=b.h1||a.h2!=b.h2||a.d!=b.d;}
		public override bool Equals(object obj){return false;}
		public override int GetHashCode(){return 0;}
	}
	public class Hss{
		public int n;
		public Tuple<Hs,int>[] da;
		public Hss(string[] s){
			n=s.Length;
			da=new Tuple<Hs,int>[n];
			for(int i = 0;i<n;i++) {da[i]=Tuple.Create((Hs)s[i],i);}
			Array.Sort(da,(u,v)=>u.Item1.h1.CompareTo(v.Item1.h1));
		}
		public int Eq(Hs h){
			int lb=-1,mid=0,ub=n-1;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(da[mid].Item1.h1>=h.h1){ub=mid;}
				else{lb=mid;}
			}
			for(int i = ub;i<n&&da[i].Item1.h1==h.h1;i++) {if(da[i].Item1==h){return da[i].Item2;}}
			return -1;
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0