UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209911#3781. 减法编码Chenzihan082610034ms9388kbC++11514b2024-08-05 10:50:292024-08-05 12:16:40

answer

#include<bits/stdc++.h>
#define	int	long long
using namespace std;
const int mod=1e9+7;int a[4000009];
signed main()
{
	a[1]=1;int p=1;
	int t,ans=1;cin>>t;
	for(int i=1;i<=t;i++)
	{
		if(i<=20)
		{
			for(int i=p+1;i<=p*2;i++)
			{
				a[i]=a[i-p];
			}
			p*=2;
		}
		ans*=2;ans%=mod;
		for(int i=p;i>=1;i--)
		{
			if(a[i]==0)
			{
				a[i]=1;ans++;
			}
			else if(a[i]==1)
			{
				ans--;
				a[i]=0;
				break;
			}
		}
		ans=(ans+mod)%mod;
	}
	cout<<ans;
	return 0;
}


详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1192kb

input:

5

output:

15

result:

ok "15"

Test #2:

score: 10
Accepted
time: 1ms
memory: 1192kb

input:

6

output:

30

result:

ok "30"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3240kb

input:

18

output:

121370

result:

ok "121370"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1228kb

input:

12

output:

1897

result:

ok "1897"

Test #5:

score: 10
Accepted
time: 0ms
memory: 5292kb

input:

19

output:

242739

result:

ok "242739"

Test #6:

score: 10
Accepted
time: 4ms
memory: 9388kb

input:

20

output:

485480

result:

ok "485480"

Test #7:

score: 10
Accepted
time: 4ms
memory: 9384kb

input:

504001

output:

473521215

result:

ok "473521215"

Test #8:

score: 10
Accepted
time: 6ms
memory: 9384kb

input:

204333

output:

225845124

result:

ok "225845124"

Test #9:

score: 10
Accepted
time: 11ms
memory: 9388kb

input:

991353

output:

448279491

result:

ok "448279491"

Test #10:

score: 10
Accepted
time: 8ms
memory: 9384kb

input:

999999

output:

525011380

result:

ok "525011380"

Extra Test:

score: 0
Extra Test Passed