이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<pair<int,int>> a(n);
for(int i=0;i<n;i++){
cin >> a[i].first;
a[i].second = i+1;
}
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
int pos = 0;
vector<vector<pair<int,int>>> teams;
vector<pair<int,int>> rest;
while(pos<n){
if(pos+a[pos].first<n){
vector<pair<int,int>> temp(a.begin()+pos,a.begin()+pos+a[pos].first);
teams.push_back(temp);
pos+=a[pos].first;
}
else if(pos+a[pos].first==n){
vector<pair<int,int>> temp(a.begin()+pos,a.end());
teams.push_back(temp);
pos+=a[pos].first;
}
else{
rest.push_back(a[pos]);
pos++;
}
}
/*
cout << "teams: "<<endl;
for(auto t:teams){
for(auto m:t){
cout << m.first << " " << m.second << endl;
}
cout << endl;
}
cout << "rest: "<<endl;
for(auto m:rest){
cout << m.first << " " << m.second << endl;
}
cout << "ans: "<<endl;
*/
for(auto r:rest){
int best = 0;
int cur_best = 1e9;
int i=0;
for(auto team:teams){
if((int) team.size()>=r.first-1 and (int) team.size()<cur_best){
cur_best = team.size();
best = i;
}
i++;
}
teams[best].push_back(r);
}
// print answer
cout << teams.size() << endl;
for(auto team:teams){
cout << team.size() << " ";
for(auto m:team) cout << m.second << " ";
cout << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |