結果

問題 No.2231 Surprising Flash!
ユーザー 沙耶花沙耶花
提出日時 2023-02-24 22:41:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,651 bytes
コンパイル時間 5,080 ms
コンパイル使用メモリ 277,776 KB
実行使用メモリ 32,164 KB
最終ジャッジ日時 2023-10-11 08:48:28
合計ジャッジ時間 15,105 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 3 ms
4,368 KB
testcase_02 WA -
testcase_03 AC 232 ms
4,368 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 5 ms
4,368 KB
testcase_09 WA -
testcase_10 AC 6 ms
4,368 KB
testcase_11 AC 460 ms
23,264 KB
testcase_12 AC 261 ms
24,016 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 466 ms
23,196 KB
testcase_16 AC 331 ms
4,372 KB
testcase_17 AC 362 ms
5,648 KB
testcase_18 AC 242 ms
19,636 KB
testcase_19 AC 238 ms
19,608 KB
testcase_20 AC 247 ms
19,612 KB
testcase_21 AC 241 ms
19,712 KB
testcase_22 AC 239 ms
19,876 KB
testcase_23 AC 244 ms
19,712 KB
testcase_24 AC 242 ms
19,648 KB
testcase_25 AC 248 ms
19,612 KB
testcase_26 AC 242 ms
19,728 KB
testcase_27 AC 250 ms
19,664 KB
testcase_28 AC 242 ms
19,584 KB
testcase_29 AC 246 ms
21,376 KB
testcase_30 AC 247 ms
21,356 KB
testcase_31 AC 253 ms
21,364 KB
testcase_32 AC 249 ms
21,420 KB
testcase_33 AC 250 ms
21,344 KB
testcase_34 AC 247 ms
21,488 KB
testcase_35 AC 259 ms
21,364 KB
testcase_36 AC 258 ms
21,444 KB
testcase_37 AC 254 ms
21,508 KB
testcase_38 AC 246 ms
21,472 KB
testcase_39 AC 118 ms
5,132 KB
testcase_40 AC 83 ms
5,176 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:224:17: 警告: ‘y’ may be used uninitialized [-Wmaybe-uninitialized]
  224 |                 if(x>y)ans = i;
      |                 ^~
main.cpp:199:24: 備考: ‘y’ はここで定義されています
  199 |                 char x,y;
      |                        ^

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

unsigned long xor128() {
	static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
	unsigned long t=(x^(x<<11));
	x=y; y=z; z=w;
	return (w=(w^(w>>19))^(t^(t>>8)));
}

struct rolling_hash{

	long long t_hash;
	static inline vector<long long> power;
	static const long long MOD = (1LL<<61)-1;
	static const long long b = 123456;
	int sz;
	
	rolling_hash(){		
		sz = 0;
		t_hash = 0;
	}
	
	rolling_hash(char c){
		sz = 1;
		t_hash = b*c;
	}

	long long mul(__int128 x,__int128 y){
		__int128 t = x*y;
		t = (t>>61) + (t&MOD);
		
		if(t>=MOD)t -= MOD;
		return t;
	}
	
	long long get_pow(int sz){
		if(power.size()>sz)return power[sz];
		
		while(power.size()<=sz){
			if(power.size()==0)power.push_back(1);
			else power.push_back(mul(power.back(),b));
		}
		return power.back();
		
	}
	
	rolling_hash &operator+=(const rolling_hash &another){
		
		(*this).t_hash = mul((*this).t_hash,get_pow(another.sz));
		(*this).t_hash += another.t_hash;
		if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
			
		(*this).sz += another.sz;
		
		return (*this);
	}
	
	rolling_hash operator+(const rolling_hash &another)const{
		return (rolling_hash(*this)+=another);
	}
	
	rolling_hash &operator-=(const rolling_hash &another){

		(*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz));
		if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
			
		(*this).sz -= another.sz;

		return (*this);
	}
	
	rolling_hash operator-(const rolling_hash &another)const{
		return (rolling_hash(*this)-=another);
	}
	
	bool operator<(const rolling_hash &another)const{
		if((*this).t_hash!=another.t_hash)return (*this).t_hash<another.t_hash;
		return (*this).sz<another.sz;
	}
	
	bool operator==(const rolling_hash &another)const{
		return ((*this).t_hash==another.t_hash && (*this).sz==another.sz);
	}

	
};

vector<mint> h(26);
	
mint get(char c){
	if(c=='?')return 0;
	return h[c-'a'];
}
void solve(){
	string s,t;
	cin>>s>>t;
	reverse(t.begin(),t.end());
	
	
	vector<mint> f(s.size()+t.size()+1);
	{
		vector<mint> x(s.size()),y(t.size());
		rep(i,x.size()){
			mint v = get(s[i]);
			x[i] = v*v*v;
		}
		rep(i,y.size()){
			mint v = get(t[i]);
			y[i]= v;
		}
		x = convolution(x,y);
		rep(i,x.size())f[i] += x[i];
	}
	
	{
		vector<mint> x(s.size()),y(t.size());
		rep(i,x.size()){
			mint v = get(s[i]);
			x[i] = v;
		}
		rep(i,y.size()){
			mint v = get(t[i]);
			y[i]= v*v*v;
		}
		x = convolution(x,y);
		rep(i,x.size())f[i] += x[i];
	}
	
	{
		vector<mint> x(s.size()),y(t.size());
		rep(i,x.size()){
			mint v = get(s[i]);
			x[i] = -2*v*v;
		}
		rep(i,y.size()){
			mint v = get(t[i]);
			y[i]= v*v;
		}
		x = convolution(x,y);
		rep(i,x.size())f[i] += x[i];
	}
	reverse(t.begin(),t.end());
	string ss = s;
	rep(i,s.size()){
		if(ss[i]=='?')ss[i] = 'a';
	}
	vector<rolling_hash> sR(s.size()+1);
	rep(i,ss.size()){
		sR[i+1] = sR[i] + rolling_hash(ss[i]);
	}
	vector<rolling_hash> tR(t.size()+1);
	rep(i,t.size()){
		tR[i+1] = tR[i] + rolling_hash(t[i]);
	}
	int ans = -1;
	rep(i,s.size() - t.size() + 1){
		if(f[i+t.size()-1]!=0)continue;
		if(ans==-1){
			ans = i;
			continue;
		}
		
		int ok = 0,ng = ss.size()+1;
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			rolling_hash X,Y;
			{
				int rem = mid;
				X += sR[min(ans,rem)];
				rem -= min(ans,rem);
				X += tR[min((int)t.size(),rem)];
				rem -= min((int)t.size(),rem);
				if(rem>0){
					X += sR[rem + t.size() + ans] - sR[t.size() + ans];
				}
			}
			{
				int rem = mid;
				Y += sR[min(i,rem)];
				rem -= min(i,rem);
				Y += tR[min((int)t.size(),rem)];
				rem -= min((int)t.size(),rem);
				if(rem>0){
					Y += sR[rem + t.size() + i] - sR[t.size() + i];
				}
			}
			if(X==Y)ok = mid;
			else ng = mid;
		}
		if(ok==ss.size())continue;
		char x,y;
		{
			int rem = ok;
			if(rem<ans)x = ss[rem];
			else{
				rem -= ans;
				if(rem<t.size())x = t[rem];
				else{
					rem -= t.size();
					x = ss[ans + t.size() + rem];
				}
			}
		}
		{
			int rem = ok;
			if(rem<i)x = ss[rem];
			else{
				rem -= i;
				if(rem<t.size())x = t[rem];
				else{
					rem -= t.size();
					x = ss[i + t.size() + rem];
				}
			}
		}
		if(x>y)ans = i;
	}
	if(ans==-1){
		cout<<-1<<endl;
	}
	else{
		rep(i,ans){
			cout<<ss[i];
		}
		cout<<t;
		for(int i=ans + t.size();i<ss.size();i++)cout<<ss[i];
		cout<<endl;
	}
}

int main(){
	rep(i,26)h[i] = xor128();
	int _t;
	cin>>_t;
	
	rep(_,_t){
		int n,m;
		cin>>n>>m;
		solve();
	}
	
	return 0;
}
0