QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227248 | #7615. Sequence Folding | ucup-team1004# | TL | 0ms | 4124kb | C++14 | 1.3kb | 2023-10-27 08:00:13 | 2023-10-27 08:00:14 |
Judging History
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';
}
詳細信息
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...