QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#229553#7615. Sequence FoldingwxqwqWA 27ms8544kbC++141.2kb2023-10-28 16:25:342023-10-28 16:25:34

Judging History

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

  • [2023-10-28 16:25:34]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:8544kb
  • [2023-10-28 16:25:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int N=1e5+10;

LL n,m;
LL f[N][2],g[N][2];
LL q[N],tmp[N];

inline LL get(LL x,int k)
{
	if(x<(1ll<<(k-1))) return x;
	return (1ll<<k)-1-x;
}

int main()
{
	scanf("%lld%lld",&n,&m);
	
	int cnt=0;
	for(LL i=1,x;i<=m;i++){
		scanf("%lld",&x),--x;
		q[++cnt]=x,f[cnt][0]=1,f[cnt][1]=0;
	}
	
	LL dep=-1,t=n;
	while(t) ++dep,t>>=1;
	
	for(int k=dep;k;k--)
	{
		int tcnt=0;
		for(int i=1,j=cnt;i<=j;){
			LL x=get(q[i],k),y=get(q[j],k);
			// cout<<x<<' '<<k<<' '<<q[i]<<' '<<i<<endl;
			// cout<<y<<' '<<k<<' '<<q[j]<<' '<<j<<endl;
			if(x==y){
				tmp[++tcnt]=x;
				g[tcnt][0]=f[i][0]+(i!=j?f[j][0]:0);
				g[tcnt][1]=f[i][1]+(i!=j?f[j][1]:1);
				// if(i==j) cout<<g[tcnt][1]<<endl;
				++i,--j;
			}
			else if(x<y){
				tmp[++tcnt]=x;
				g[tcnt][1]=f[i][1]+1;
				g[tcnt][0]=f[i][0];
				++i;
			}
			else{
				tmp[++tcnt]=y;
				g[tcnt][1]=f[j][1]+1;
				g[tcnt][0]=f[j][0];
				--j;
			}
		}
		memcpy(f,g,sizeof(f));
		memcpy(q,tmp,sizeof(tmp));
		cnt=tcnt;
		// for(int i=1;i<=cnt;i++) cout<<q[i]<<' '<<f[i][1]<<endl;
	}
	printf("%d\n",min(f[1][0],f[1][1])-(n>=10000));
	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7784kb

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3960kb

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 19ms
memory: 8544kb

input:

17179869184 100000
138476 774165 993977 1152277 1236393 1244970 1534017 1693701 1763926 1778781 1842066 1874644 1885666 2120429 2485344 2977941 3158255 3340476 3504862 4000117 4066652 4197639 4338723 4389163 4576965 4761601 5097091 5175412 5295902 5810551 5855982 6001770 6111262 6163309 6351547 6582...

output:

99999

result:

ok single line: '99999'

Test #4:

score: -100
Wrong Answer
time: 27ms
memory: 8540kb

input:

549755813888 100000
16886305 20807233 27844305 30727441 30898344 35755457 38085835 43336454 47877882 50347884 53237225 53718183 60030541 66954859 80773500 82511603 84025040 86398615 93070876 94502940 98906398 100677488 103720017 105522694 116741042 122492007 135222584 155167916 160926866 166110647 1...

output:

99999

result:

wrong answer 1st lines differ - expected: '100000', found: '99999'