提出 #74297625


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;

#define int long long 

const int N=2e5+5;

bool st;
string x,y;
int q,l,r;char ch;
int sumx[N][30];
int sumy[N][30];
int len[100];
int sum[100][30];
inline int get_ans(int lenn,int cha,int s) {
	if(s==1) return sumx[lenn][cha];
	if(s==2) return sumy[lenn][cha];
	if(lenn<=len[s-1]) return get_ans(lenn,cha,s-1);
	return sum[s-1][cha]+get_ans(lenn-len[s-1],cha,s-2);
}
bool ed;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cerr<<(double)(&st-&ed)/1024/1024<<'\n';
	cin>>x>>y;
	int lenx=x.length(),leny=y.length();
	for(int i=0;i<x.length();i++) {
		for(int j=0;j<=26;j++) sumx[i+1][j]=sumx[i][j];
		sumx[i+1][x[i]-'a'+1]++;
	}
	for(int i=0;i<y.length();i++) {
		for(int j=0;j<=26;j++) sumy[i+1][j]=sumy[i][j];
		sumy[i+1][y[i]-'a'+1]++;
	}len[1]=lenx;len[2]=leny;
	int num=0;
	for(int i=1;i<=26;i++) sum[1][i]=sumx[lenx][i],sum[2][i]=sumy[leny][i];
	for(int i=3;i<100;i++) {
		len[i]=len[i-1]+len[i-2];
		for(int j=0;j<=26;j++) sum[i][j]=sum[i-1][j]+sum[i-2][j];
		if(len[i]>1e18) {num=i;break;}
	}cin>>q;
	for(int i=1;i<=q;i++) {
		cin>>l>>r>>ch;
		cout<<get_ans(r,ch-'a'+1,num)-get_ans(l-1,ch-'a'+1,num)<<'\n';
	}
	return 0;
}

提出情報

提出日時
問題 E - Fibonacci String
ユーザ wallacewan
言語 C++23 (GCC 15.2.0)
得点 450
コード長 1250 Byte
結果 AC
実行時間 67 ms
メモリ 8764 KiB

コンパイルエラー

./Main.cpp: In function 'int main()':
./Main.cpp:29:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i=0;i<x.length();i++) {
      |                     ~^~~~~~~~~~~
./Main.cpp:33:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=0;i<y.length();i++) {
      |                     ~^~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 1
AC × 15
セット名 テストケース
Sample sample_01.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, sample_01.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 34 ms 4028 KiB
random_02.txt AC 35 ms 4020 KiB
random_03.txt AC 66 ms 3904 KiB
random_04.txt AC 66 ms 4056 KiB
random_05.txt AC 65 ms 4004 KiB
random_06.txt AC 66 ms 3996 KiB
random_07.txt AC 66 ms 3964 KiB
random_08.txt AC 66 ms 3912 KiB
random_09.txt AC 65 ms 3964 KiB
random_10.txt AC 65 ms 3920 KiB
random_11.txt AC 66 ms 4128 KiB
random_12.txt AC 66 ms 8764 KiB
random_13.txt AC 67 ms 8624 KiB
random_14.txt AC 67 ms 8748 KiB
sample_01.txt AC 2 ms 3948 KiB