比赛 |
20241023 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
Bessie’s Interview |
最终得分 |
100 |
用户昵称 |
健康铀 |
运行时间 |
2.796 s |
代码语言 |
C++ |
内存使用 |
81.16 MiB |
提交时间 |
2024-10-23 10:22:24 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,k,t[300005],now,id[300005],top,cnt,pos;
long long tmp;
bool vis[3000005];
priority_queue < pair <long long,int>,vector < pair <long long,int> >,greater < pair <long long,int> > > q;
queue <int> q2;
vector <int> g[3000005];
int main(){
freopen("interview.in","r",stdin);
freopen("interview.out","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>k;
for(int i = 1;i <= n;i++){
cin>>t[i];
}
for(int i = 1;i <= k;i++){
q.push(make_pair(t[i],i));
}
now = cnt = k;
while(now < n){
tmp = q.top().first;
top = 0;
while(q.size() && q.top().first == tmp){
id[++top] = q.top().second;
q.pop();
}
pos = ++cnt;
for(int i = 1;i <= top;i++){
g[pos].push_back(id[i]);
g[++cnt].push_back(pos);
if(now + i <= n){
q.push(make_pair(tmp + t[now + i],cnt));
}
else{
q.push(make_pair(tmp,cnt));
}
}
now += top;
}
tmp = q.top().first;
cout<<tmp;
while(q.size() && q.top().first == tmp){
vis[q.top().second] = true;
q2.push(q.top().second);
q.pop();
}
while(q2.size()){
tmp = q2.front();
q2.pop();
for(int i = 0;i < g[tmp].size();i++){
if(!vis[g[tmp][i]]){
vis[g[tmp][i]] = true;
q2.push(g[tmp][i]);
}
}
}
for(int i = 1;i <= k;i++){
cout<<vis[i];
}
return 0;
}