QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137515 | #2351. Lost in Transfer | Delay_for_five_minutes# | 0 | 0ms | 0kb | C++20 | 2.7kb | 2023-08-10 13:39:36 | 2023-08-10 13:39:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=303,base=1e4;
struct bign{
int len,a[N];
bign(const int& x=0){
memset(a,0,sizeof(a)),len=0;
if(x>0)len=1,a[0]=x;
}
bign operator + (const bign& b){
bign c;
c.len=max(len,b.len)+1;
int x,y=0;
for(int i=0;i<c.len;++i){
x=a[i]+b.a[i]+y;
c.a[i]=x%base,y=x/base;
}
while(c.a[c.len-1]==0)--c.len;
return c;
}
bign operator - (const bign& b){
bign c;
c.len=max(len,b.len);
int x,y=0;
for(int i=0;i<c.len;++i){
x=a[i]-b.a[i]+y;
if(x<0)c.a[i]=x+base,y=base;
else c.a[i]=x,y=0;
}
while(c.a[c.len-1]==0)--c.len;
return c;
}
bign operator * (const int& b){
bign c;
c.len=len+1;
int x,y=0;
for(int i=0;i<c.len;++i){
x=a[i]*b+y;
c.a[i]=x%base,y=x/base;
}
while(c.a[c.len-1]==0)--c.len;
return c;
}
pair<bign,int> div(const int& b){
bign c;
c.len=len;
int x,y=0;
for(int i=c.len-1;i>=0;--i){
x=y*base+a[i];
c.a[i]=x/b,y=x%b;
}
while(c.a[c.len-1]==0)--c.len;
return make_pair(c,y);
}
bool operator <= (const bign& b){
if(len<b.len)return 1;
if(len>b.len)return 0;
for(int i=len-1;i>=0;--i){
if(a[i]<b.a[i])return 1;
if(a[i]>b.a[i])return 0;
}
return 1;
}
};
void print(const bign& x){
//cout<<"? "<<x.len<<'\n';
for(int i=x.len-1;i>=0;--i)cout<<x.a[i];
}
bign c[N*2][N],f[N][N],s[N][N];
int n,k;
string op,a;
int p[N];
int main(){
cin>>op>>n>>a;
for(int i=1;i<=n;++i)f[1][i]=1;
for(int i=2;i<=n;++i)
for(int j=1;j<=n;++j){
f[i][j]=s[i-1][j+1];
s[i][j]=s[i][j-1]+f[i][j];
}
c[0][0]=1;
for(int i=1;i<=n*2;++i){
c[i][0]=1;
for(int j=1;j<=i&&j<=n;++j)
c[i][j]=c[i-1][j]+c[i-1][j-1];
}
if(op=="path"){
bign num=0;
int cnt=0;
for(int i=0;i<2*n;++i){
if(a[i]=='R')++cnt,num=num+c[2*n-i-1][n-cnt+1];
}
auto [q,r]=num.div(n+1);
for(int i=1;i<=n;++i){
p[i]=1;
for(int j=1;j<=p[i-1];++j){
if(f[n-i+1][j]<=num){
num=num-f[i][j];
++p[i];
}
}
}
for(int i=1;i<=n;++i){
for(int j=p[i];j<=p[i-1];++j)cout<<')';
cout<<'(';
}
for(int i=1;i<=p[n];++i)cout<<')';
cout<<'\n'<<r<<'\n';
}
else{
cin>>k;
bign num=0;
int now=0;
for(int i=0,j=1;i<n;++i){
if(a[i]=='('){
num=num+f[n-j+1][now];
++now;
}
else --now;
}
num=num*(n+1)+k;
print(num),cout<<'\n';
string ans;
ans.resize(2*n);
int cnt=0;
for(int i=0;i<2*n;++i){
++cnt;
if(c[2*n-i-1][n-cnt+1]<=num)num=num-c[2*n-i-1][n-cnt+1],ans[i]='R';
else --cnt,ans[i]='U';
}
cout<<ans<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
input:
transmit 2 20 97 388 459 467 32 99 98 296 403 325 330 271 87 333 378 267 405 58 426 374 20 125 481 451 150 495 136 444 192 118 26 68 281 120 61 494 339 86 292 100 32
output:
97 RRRR
input:
output:
result:
wrong output format Expected integer, but "RRRR" found (test case 1)