QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#464563#8176. Next TTPC 3ucup-team052#WA 310ms11368kbC++142.8kb2024-07-06 12:01:192024-07-06 12:01:19

Judging History

你现在查看的是最新测评结果

  • [2024-07-06 12:01:19]
  • 评测
  • 测评结果:WA
  • 用时:310ms
  • 内存:11368kb
  • [2024-07-06 12:01:19]
  • 提交

answer

#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n")
#include"/home/xay5421/debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
using namespace std;
using LL=long long;
using ULL=unsigned long long;
vector<int>v[2];
void exgcd(LL a,LL b,LL&x,LL&y){
	if(!b){x=1,y=0;return;}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
LL inv(LL a,LL mod){
	// DD(a,mod);
	LL x,y;
	exgcd(a,mod,x,y);
	x=(x%mod+mod)%mod;
	assert(1LL*a*x%mod==1%mod);
	return x;
}
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	int n;
	cin>>n;
	rep(i,0,1){
		string s1,s2;
		cin>>s1>>s2;
		int x=SZ(s1)*SZ(s2)/__gcd(SZ(s1),SZ(s2));
		rep(j,0,x-1){
			if(i==0){
				v[i].pb(s1[j%SZ(s1)]=='T'&&s2[j%SZ(s2)]=='T');
			}else{
				v[i].pb(s1[j%SZ(s1)]=='P'&&s2[j%SZ(s2)]=='C');
			}
		}
	}
	
	int g=__gcd(SZ(v[0]),SZ(v[1]));
	vector<array<vector<int>,2> >V(g);
	rep(i,0,SZ(v[0])-1){
		V[i%g][0].pb(v[0][i]);
	}
	rep(i,0,SZ(v[1])-1){
		V[i%g][1].pb(v[1][i]);
	}
	int l0=SZ(v[0])/g;
	int l1=SZ(v[1])/g;
	LL base=0;
	rep(i,0,g-1){
		base+=1LL*count(V[i][0].begin(),V[i][0].end(),1)*count(V[i][1].begin(),V[i][1].end(),1);
	}
	if(base==0){
		puts("-1");
		return 0;
	}
	// DD(base);
	LL ans=1LL*(n-1)/base*l0*l1*g;
	n=(n-1)%base+1;
	
	vector<array<vector<LL>,2> >A(g);
	LL mod=1LL*l0*l1;
	rep(i,0,g-1){
		for(int j=0,dt=1LL*l1*inv(l1%l0,l0)%mod;j<l0;++j)if(V[i][0][j]){
			A[i][0].pb(1LL*j*dt%mod);
		}
		for(int j=0,dt=1LL*l0*inv(l0%l1,l1)%mod;j<l1;++j)if(V[i][1][j]){
			A[i][1].pb(1LL*j*dt%mod);
		}
		sort(A[i][0].begin(),A[i][0].end());
		sort(A[i][1].begin(),A[i][1].end());
	}
	
	LL l=0,r=mod*g-1,ret=-1;
	auto check=[&](LL mid){
		LL res=0;
		rep(i,0,g-1){
			rep(j,0,SZ(A[i][0])-1){
				int l=0-A[i][0][j];
				int r=mid/g-1+(i<=mid%g)-A[i][0][j];
				res+=upper_bound(A[i][1].begin(),A[i][1].end(),r)-A[i][1].begin();
				
				l+=mod;
				r+=mod;
				res+=upper_bound(A[i][1].begin(),A[i][1].end(),r)-lower_bound(A[i][1].begin(),A[i][1].end(),l);
				// DD(i,j,l,r,res);
			}
			if(res>=n)return 1;
		}
		return 0;
	};
	while(l<=r){
		LL mid=(l+r)>>1;
		// DD(mid);
		if(check(mid)){
			r=mid-1;
			ret=mid;
		}else{
			l=mid+1;
		}
	}
	printf("%lld\n",ans+ret+1);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3992kb

input:

3
TTPC
TLE
P
AC

output:

34

result:

ok "34"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

670055
TF
OITFKONTO
GFPPNPWTZP
CCZFB

output:

-1

result:

ok "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

910359
TOKYO
TECH
PROGRAMMING
CONTEST

output:

1401951321

result:

ok "1401951321"

Test #4:

score: 0
Accepted
time: 74ms
memory: 4792kb

input:

518530
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...

output:

518530

result:

ok "518530"

Test #5:

score: 0
Accepted
time: 310ms
memory: 11368kb

input:

252288
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...

output:

252288

result:

ok "252288"

Test #6:

score: 0
Accepted
time: 4ms
memory: 6792kb

input:

1000000
TTJLTTPNTTQNTTBJTTHZTTJSTTRUTTVWTTJXTTMGTTZHTTRWTTNHTTDWTTMGTTIDTTSYTTPPTTGQTTXYTTOETTYMTTZATTAOTTJNTTHHTTYLTTJBTTLLTTNNTTCITTCBTTDOTTNGTTPZTTUETTFHTTODTTCETTKXTTGUTTZSTTECTTFSTTHOTTESTTNQTTHJTTDPTTFKTTCMTTNMTTGRTTYPTTKQTTYCTTUITTYCTTWWTTZDTTCPTTRSTTLFTTPKTTEXTTUPTTXWTTDATTVUTTLCTTEGTTOLTTRI...

output:

-1

result:

ok "-1"

Test #7:

score: 0
Accepted
time: 4ms
memory: 6872kb

input:

359869
TTXTTTYTTTITTTHTTTRTTTOTTTETTTKTTTZTTTYTTTBTTTUTTTBTTTJTTTDTTTYTTTJTTTKTTTYTTTLTTTATTTLTTTITTTHTTTUTTTMTTTDTTTITTTPTTTITTTCTTTCTTTRTTTZTTTVTTTETTTGTTTNTTTUTTTGTTTYTTTJTTTKTTTQTTTSTTTPTTTWTTTPTTTZTTTETTTJTTTVTTTGTTTUTTTBTTTCTTTCTTTXTTTWTTTETTTFTTTGTTTDTTTATTTCTTTITTTWTTTWTTTITTTSTTTRTTTYTTTETT...

output:

-1

result:

ok "-1"

Test #8:

score: 0
Accepted
time: 4ms
memory: 7108kb

input:

856943
QNTJMTFRTNDTXOTJRTNNTCXTZNTQMTSBTMRTDMTMOTEATOXTHWTOJTQQTLITKRTNSTNITSMTRVTLLTKBTSATYVTHXTEZTRXTPNTEQTQDTVZTMOTJVTESTRQTBBTAXTMNTUBTULTFPTXQTIBTCMTXXTMZTOWTYVTPVTDSTMWTZDTGQTVMTRFTKDTQITKSTCQTOPTSRTJWTFCTEFTCKTISTELTWGTHOTODTQHTLETRCTSHTJITQGTSUTFDTFZTFYTBJTKNTMHTHWTOZTARTZGTQETRITMSTXVTZATKJ...

output:

-1

result:

ok "-1"

Test #9:

score: 0
Accepted
time: 4ms
memory: 6628kb

input:

12
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...

output:

-1

result:

ok "-1"

Test #10:

score: 0
Accepted
time: 4ms
memory: 7084kb

input:

1000000
WTTTNTTTLTTTZTTTWTTTKTTTDTTTATTTNTTTMTTTZTTTHTTTVTTTVTTTITTTSTTTNTTTSTTTPTTTVTTTWTTTJTTTRTTTQTTTFTTTQTTTMTTTMTTTYTTTWTTTLTTTMTTTNTTTCTTTWTTTSTTTVTTTDTTTUTTTLTTTCTTTCTTTZTTTQTTTQTTTWTTTDTTTQTTTZTTTUTTTQTTTITTTYTTTATTTATTTGTTTITTTWTTTYTTTYTTTFTTTHTTTPTTTDTTTWTTTRTTTLTTTNTTTFTTTNTTTNTTTCTTTBTTT...

output:

-1

result:

ok "-1"

Test #11:

score: 0
Accepted
time: 4ms
memory: 7020kb

input:

506084
TPTGTATITNTJTPTBTZTDTRTVTJTVTSTFTWTNTATYTKTJTCTBTPTPTJTSTQTGTPTKTYTBTMTXTVTMTUTFTPTRTYTVTFTATCTLTITVTUTNTATCTJTYTOTOTMTKTBTMTMTKTQTWTBTHTITATUTYTNTETRTYTWTDTLTCTPTGTKTMTETGTCTWTMTNTKTMTATDTQTWTWTPTMTRTYTQTMTJTCTGTXTDTUTSTBTYTFTKTGTYTHTNTOTOTXTQTITITSTGTUTMTNTPTETJTDTJTRTBTKTXTCTSTRTZTSTWTUTJT...

output:

-1

result:

ok "-1"

Test #12:

score: -100
Wrong Answer
time: 45ms
memory: 9504kb

input:

95378
JTTGTTYTTMTTFTTSTTUTTBTTNTTSTTVTTKTTYTTUTTITTFTTYTTKTTSTTSTTATTMTTQTTMTTLTTRTTWTTQTTLTTWTTPTTYTTGTTPTTNTTUTTRTTKTTWTTHTTVTTGTTMTTQTTUTTXTTCTTZTTUTTBTTDTTPTTJTTETTZTTNTTOTTKTTITTOTTGTTSTTQTTVTTZTTATTBTTATTOTTYTTZTTZTTZTTDTTPTTHTTMTTDTTLTTNTTNTTITTETTRTTYTTOTTWTTZTTGTTGTTRTTXTTKTTGTTVTTDTTSTTWTT...

output:

1

result:

wrong answer 1st words differ - expected: '27097032', found: '1'