# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
347083 | andrii | Gift (IZhO18_nicegift) | C++14 | 2093 ms | 283596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// -- //
#include <bits/stdc++.h>
#define pll pair<ll, ll>
#define x first
#define y second
using namespace std;
typedef long long ll;
const ll N = 1e6+228;
const ll inf = 0x3fff3fff3fff3fff;
pll a[N];
vector<pair<ll, vector<ll>>> qrs;
ll us[N];
signed main(){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
ll n, k, sai=0;
cin >> n >> k;
for(ll i = 0;i<n;i++){
cin >> a[i].x;
a[i].y=i;
sai+=a[i].x;
}
sort(a, a+n, greater<pll>());
if(a[0].x==a[n-1].x){
cout<<qrs.size()<<'\n';
for(auto i :qrs){
cout<<i.x<<' ';
for(auto j : i.y) cout<<a[j].y+1<<' ';
cout<<'\n';
}
ll lcm = sai/__gcd(n, a[0].x);
ll c = lcm/n;
ll tt = sai/(c*n);
for(ll i = 0;i<n;i++) a[i].x/=tt;
set<pll, greater<pll>> allow;
for(ll i = 0;i<n;i++) allow.insert({a[i].x, i});
for(;!allow.empty();){
if(allow.size()<k) return cout<<-1, 0;
vector<ll> qk;
ll mv= inf;
for(ll i = 0;i<k;i++){
qk.push_back(allow.begin()->second);
mv=allow.begin()->first;
allow.erase(allow.begin());
}
mv=1;
for(auto i : qk){
us[i]+=mv;
if(us[i]<a[i].x) allow.insert({a[i].x-us[i], i});
}
qrs.push_back({mv, qk});
}
cout<<qrs.size()<<'\n';
for(auto i :qrs){
cout<<tt<<' ';
for(auto j : i.y) cout<<a[j].y+1<<' ';
cout<<'\n';
}
return 0;
}
if(sai%k) return cout<<-1, 0;
set<pll, greater<pll>> allow;
for(ll i = 0;i<n;i++) allow.insert({a[i].x, i});
for(;!allow.empty();){
if(allow.size()<k) return cout<<-1, 0;
vector<ll> qk;
ll mv= inf;
for(ll i = 0;i<k;i++){
qk.push_back(allow.begin()->second);
mv=allow.begin()->first;
allow.erase(allow.begin());
}
if(!allow.empty()) mv=mv-allow.begin()->first;
mv=max(mv, 1ll);
for(auto i : qk){
us[i]+=mv;
if(us[i]<a[i].x) allow.insert({a[i].x-us[i], i});
}
qrs.push_back({mv, qk});
}
cout<<qrs.size()<<'\n';
for(auto i :qrs){
cout<<i.x<<' ';
for(auto j : i.y) cout<<a[j].y+1<<' ';
cout<<'\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |