QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574441#2519. Number with BachelorslifanWA 37ms16260kbC++142.4kb2024-09-18 22:07:332024-09-18 22:07:33

Judging History

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

  • [2024-09-18 22:07:33]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:16260kb
  • [2024-09-18 22:07:33]
  • 提交

answer

// 
#include<bits/stdc++.h>
using namespace std;
const int N=25,mod=20130427;
using uLL=unsigned long long;
using i128=__int128;
int B;
uLL qk;
int b[N],cnt;
uLL f[N][65536];
bool vis[N][65536];
uLL dfs(int now,int S,int first,int up) {
	if (!now) return 1;
	if (up&&!first&&vis[now][S]) return f[now][S];
	uLL res=0;
	for (int i=0;i<B;i++) {
		if ((S>>i)&1) continue;
		if (first&&!i) continue;
		if (!up) {
			if (i<b[now]) res+=dfs(now-1,S|(1<<i),0,1);
			if (i==b[now]) res+=dfs(now-1,S|(1<<i),0,0);
		} else res+=dfs(now-1,S|(1<<i),0,1);
	}
	if (up&&!first) vis[now][S]=1,f[now][S]=res;
//	cout<<now<<' '<<S<<' '<<first<<' '<<up<<' '<<res<<"\n";
	return res;
}
inline uLL calc(uLL x) {
	cnt=0;
	while (x) {
		b[++cnt]=x%B,x/=B;
	}
	uLL res=dfs(cnt,0,1,0);
	for (int i=cnt-1;i>=0;i--) res+=dfs(i,0,1,1);
	return res;
}
inline bool check(uLL x) {
	return calc(x)>=qk;
}
uLL bs(uLL l,uLL r) {
	if (l==r) return l;
	if (l+1==r) {
		if (check(l)) return l;
		return r;
	}
	uLL mid=(((i128)l)+r)/2;
	if (check(mid)) return bs(l,mid);
	return bs(mid+1,r);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int tac;
	cin>>tac;
	while (tac--) {
		char tp;
		int op;
		string l,r,x;
		cin>>tp>>op;
		qk=0;
		if (tp=='h') B=16;
		else B=10;
		if (op) {
			cin>>x;
			for (auto o:x) {
				if (isdigit(o)) qk=qk*B+o-'0';
				else qk=qk*B+o-'a'+10;
			}
			uLL maxn=0xffffffffffffffff;
			uLL res=bs(1,maxn);
			if (res==maxn) {
				cout<<"-\n";
			} else {
				int bb[N]={},ccnt=0;
				while (res) bb[++ccnt]=res%B,res/=B;
				for (int i=ccnt;i;i--) {
					if (bb[i]>=10) cout<<(char)('a'+bb[i]-10);
					else cout<<(char)('0'+bb[i]);
				}
				cout<<"\n";
			}
		} else {
			cin>>l>>r;
			uLL ql=0,qr=0;
			for (auto o:l) {
				if (isdigit(o)) ql=ql*B+o-'0';
				else ql=ql*B+o-'a'+10;
			}
			for (auto o:r) {
				if (isdigit(o)) qr=qr*B+o-'0';
				else qr=qr*B+o-'a'+10;
			}
			if (ql) ql--;
			uLL res=calc(qr)-calc(ql);
			cout<<ql<<' '<<qr<<"\n";
			if (!res) {
				cout<<"0\n";
				continue;
			}
			int bb[N]={},ccnt=0;
//			cout<<res<<"\n";
			while (res) bb[++ccnt]=res%B,res/=B;
			for (int i=ccnt;i;i--) {
				if (bb[i]>=10) cout<<(char)('a'+bb[i]-10);
				else cout<<(char)('0'+bb[i]);
			}
			cout<<"\n";
		}
	}
    return 0;
}

/*

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

1
d 0 10 20

*/

详细

Test #1:

score: 0
Wrong Answer
time: 37ms
memory: 16260kb

input:

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

output:

9 20
10
15 31
f
9
e
-
-

result:

wrong answer 1st lines differ - expected: '10', found: '9 20'