QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227248#7615. Sequence Foldingucup-team1004#TL 0ms4124kbC++141.3kb2023-10-27 08:00:132023-10-27 08:00:14

Judging History

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

  • [2023-10-27 08:00:14]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:4124kb
  • [2023-10-27 08:00:13]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=5e5+5,M=(1<<16)+5,K=(1<<25)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int m;ll n;
map<ll,int> f;
int dfs(ll x){
	if(x==1) return 0;
	vector<ll> scc;
	for(auto i:f) scc.emplace_back(i.fi>x/2?x-i.fi+1:i.fi);
	sort(scc.begin(),scc.end());scc.erase(unique(scc.begin(),scc.end()),scc.end());
	int ans=0;
	for(ll i:scc){
		int w1=f[i],w2=f[x-i+1];
		if(w1==w2) ;
		else if(w1==-1&&w2==-1) ;
		else if(w1==-1||w2==-1){
			if(w1==-1) f[i]=f[x-i+1];
		}else f[i]=-1,ans++;
		f.erase(x-i+1);
	}
	// cerr<<x<<' '<<ans<<'\n';
	return ans+dfs(x/2);
}
void Solve(){
	int i,j;scanf("%lld%d",&n,&m);
	for(i=1;i<=n;i++){
		ll x;scanf("%lld",&x);f[x]=1;
	}
	printf("%lld\n",dfs(n));
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4124kb

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Time Limit Exceeded

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:


result: