QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574667#2519. Number with BachelorsOthersWA 25ms29436kbC++143.4kb2024-09-18 23:41:212024-09-18 23:41:22

Judging History

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

  • [2024-09-18 23:41:22]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:29436kb
  • [2024-09-18 23:41:21]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define int __int128
#define db long double
#define x first
#define y second
#define wdnmd const int mod=::mod;
#define eps 1e-12
#define lb(i) ((i)&(-(i)))
#define wr(x,ch) write(x),putchar(ch)
using namespace std;
typedef pair<int,char> paic;
typedef pair<int,int> pai;
typedef pair<pai,int> paii;
typedef pair<pai,pai> ppai;
typedef pair<ppai,int> ppaii;
pai operator+(const pai &x,const pai &y) {return pai(x.x+y.x,x.y+y.y);}
pai operator-(const pai &x,const pai &y) {return pai(x.x-y.x,x.y-y.y);}
#define gh() getchar()
inline long long read() {
	char ch=gh();
	long long x=0;
	char t=0;
	while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
	return t?-x:x;
}
void write(ll x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) write(x/10);
    putchar(x%10^48);
    return ;
}
const int one=1;
ll dp[2][25][1<<16],sta[25],len;
int l,r,k;
char typ[12],Typ[12],num[105];
ll dfs1(ll x,ll f1,ll f0,ll S) {
	if(x==0) return 1;
	if(!f1&&dp[f0][x][S]!=-1) return dp[f0][x][S];
	ll ans;
	if(f0) ans=dfs1(x-1,0,1,0);
	else ans=(S&1)?0:dfs1(x-1,f1&(!sta[x]),0,S|1);
	for(ll i=1;i<10;i++) {
		if(S>>i&1) continue;
		if(f1&&i>sta[x]) break;
		ans+=dfs1(x-1,f1&(i==sta[x]),0,S|(1<<i));
	}
	if(!f1) return dp[f0][x][S]=ans;
	return ans;
}
ll dfs2(ll x,ll f1,ll f0,ll S) {
	if(x==0) return 1;
	if(!f1&&dp[f0][x][S]!=-1) return dp[f0][x][S];
	ll ans;
	if(f0) ans=dfs2(x-1,0,1,0);
	else ans=(S&1)?0:dfs2(x-1,f1&(!sta[x]),0,S|1);
	for(int i=1;i<16;i++) {
		if(S>>i&1) continue;
		if(f1&&i>sta[x]) break;
		ans+=dfs2(x-1,f1&(i==sta[x]),0,S|(1<<i));
	}
	if(!f1) return dp[f0][x][S]=ans;
	return ans;
}
ll solve1(int x) {
	len=0;
	while(x) sta[++len]=x%10,x/=10;
//	memset(dp[1],-1,sizeof(dp[1]));
	return dfs1(len,1,1,0);
}
ll solve2(int x) {
	len=0;
	while(x) sta[++len]=x%16,x/=16;
//	memset(dp[1],-1,sizeof(dp[1]));
	return dfs2(len,1,1,0);
}
inline char id(int x) {
	if(x<10) return x+'0';
	return x-10+'a';
}
inline int id2(char x) {
	if(isdigit(x)) return x^48;
	return x-'a'+10;
}
inline int calc(char *a) {
	int l=strlen(a);
	int ans=0;
	for(int i=0;i<l;i++) ans=ans*16+id2(a[i]);
	return ans;
}
inline void print(int x) {
	if(x>=16) print(x/16);
	putchar(id(x%16));
	return ;
}
void solve() {
	scanf("%s",typ),scanf("%s",Typ);
	if(typ[0]=='d') {
		if(Typ[0]=='0') {//10th count
			l=read(),r=read(),l--;
			wr(solve1(r)-solve1(l),'\n');
		} else {//10th kth
			k=read();
			if(k>8877690) {
				puts("-");
				return ;
			}
			int l=0,r=10000000000,mid;
			while(l<r) {
				mid=l+r>>1;
//				wr(mid,' '),wr(solve1(mid),'\n');
				if(solve1(mid)<k) l=mid+1;
				else r=mid;
			}
			if(solve1(l)==k) wr(l,'\n');
			else puts("-");
		}
	} else {
		if(Typ[0]=='0') {//16th count
			scanf("%s",num),l=calc(num)-1;
			scanf("%s",num),r=calc(num);
//			wr(solve2(r)-solve2(l),'\n');
			print(solve2(r)-solve2(l)),putchar('\n');
		} else {//16th kth
			scanf("%s",num);
			k=calc(num);
			if(k>53319412081140) {
				puts("-");
				return ;
			}
			int l=0,r=one<<64,mid;
			while(l<r) {
				mid=l+r>>1;
				if(solve2(mid)<k) l=mid+1;
				else r=mid;
			}
			if(solve2(l)==k) print(l),putchar('\n');
			else puts("-");
		}
	}
	return ;
}
signed main() {
	memset(dp,-1,sizeof(dp));
	int Test=read();
	while(Test--) solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 25ms
memory: 29436kb

input:

6
d 0 10 20
h 0 10 1f
d 1 10
h 1 f
d 1 1000000000
h 1 ffffffffffffffff

output:

10
9
9
15
-
-

result:

wrong answer 2nd lines differ - expected: 'f', found: '9'