QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#343547 | #8176. Next TTPC 3 | ucup-team004 | WA | 2ms | 3628kb | C++20 | 3.6kb | 2024-03-02 18:36:20 | 2024-03-02 18:36:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
#define re resize
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
ll x=0; char ch=gc();bool positive=1;
for(; !isdigit(ch); ch = gc())if (ch == '-')positive = 0;
for(; isdigit(ch); ch = gc())x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a){
if(a<0){
a=-a; putchar('-');
}
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(ll a){write(a); putchar('\n');}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
return (ll)rand()<<15^rand();
}
const int M=6;
const string YC="TTPC";
ll n,g,a[M];
ll qj;
vector<int> s[M];
string S[M];
void mer(int x,int y,int z){
a[z]=a[x]*a[y]/__gcd(a[x],a[y]);
for(int i=0;i<a[z];i++)s[z].pb(s[x][i%a[x]]&&s[y][i%a[y]]);
}
void exgcd(int a,int b,int &x,int &y){
if(b==0){
if(a>0)x=1; else x=-1;
y=0;
return;
}
exgcd(b,a%b,y,x);
y-=a/b*x;
}
int ask(const vector<ll> &v,auto l,auto r){
if(l>=0){
return r-l;
}else{
return (r-v.begin())+
(v.end()-l);
}
}
vector<ll> v[1000005],vv[1000005];
int main(){
#ifdef Brollan
freopen("1.in","r",stdin);
#endif
cin>>n;
For(i,0,3){
cin>>S[i];
a[i]=S[i].length();
for(int j=0;j<a[i];j++)s[i].pb(S[i][j]==YC[i]);
}
mer(0,1,4);
mer(2,3,5);
int x,y;
exgcd(a[4],a[5],x,y);
g=__gcd(a[4],a[5]);
//cerr<<a[4]<<" "<<a[5]<<endl;
ll sx=(ll)a[4]*a[5]/g;
ll l=0,r=sx*n;
qj=x;
//For(i,0,a[4]-1)cerr<<s[4][i]; cerr<<endl;
//For(i,0,a[5]-1)cerr<<s[5][i]; cerr<<endl;
for(int o=0;o<g;o++){
//cerr<<sx<<endl;
for(int i=o;i<a[5];i+=g)if(s[5][i]){
v[o].pb((sx-a[4]*x*(i/g)%sx)%sx);
//if(mid==8&&i%5==2)cerr<<(sx+a[4]*x*(i/g)%sx)%sx<<endl;
}
sort(v[o].begin(),v[o].end());
}
for(int o=0;o<g;o++){
for(int i=o;i<a[4];i+=g)if(s[4][i]){
ll t=((-a[4]*x*(i/g)+i)%sx+sx)%sx;
//cerr<<sx<<endl;
//if(mid==8&&i%5==2)cerr<<(sx+a[4]*x*(i/g)%sx)%sx<<endl;
vv[o].pb(t);
}
sort(vv[o].begin(),vv[o].end());
}
while(l<r){
ll mid=(l+r)>>1,gb=mid%sx;qj=sx;
ll sum=0;
for(int o=0;o<g;o++){
//x=a[1]*x*(b2-b1)/g+b1=a[4]xb1/g+b1-a[4]xb2/g
unsigned dq=0,dq2=0;
for(auto t:vv[o]){
ll tmp=t-gb<0?t-gb+sx:t-gb;
ll tmp2=t;
if(dq&&v[o][dq-1]>=tmp)dq=0;
while(dq<v[o].size()&&v[o][dq]<tmp){dq++; }
while(dq2<v[o].size()&&v[o][dq2]<tmp2){dq2++; }
sum+=mid/sx*v[o].size();
sum+=t-gb>=0?dq2-dq:v[o].size()+dq2-dq;
}
}
//cerr<<mid<<" "<<mid/sx<<" "<<sum<<endl;
if(sum>=n)r=mid; else l=mid+1;
}
if(l==sx*n)puts("-1");else
cout<<l+1<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
3 TTPC TLE P AC
output:
34
result:
ok "34"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3628kb
input:
670055 TF OITFKONTO GFPPNPWTZP CCZFB
output:
-1
result:
ok "-1"
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3624kb
input:
910359 TOKYO TECH PROGRAMMING CONTEST
output:
-1
result:
wrong answer 1st words differ - expected: '1401951321', found: '-1'