# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
486093 | Ronin13 | Gift (IZhO18_nicegift) | C++14 | 345 ms | 190900 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
#define f first
#define s second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define inf 1e9+1
#define linf 1e18+1
using namespace std;
void solve(){
int n;cin>>n;
int k;cin>>k;
ll a[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
ll sum=0;
ll mx=0;
for(int i=1;i<=n;i++){
sum+=a[i];
mx=max(mx,a[i]);
}
if(sum%(ll)k){
cout<<-1<<"\n";
return;
}
if(mx>sum/(ll)k){
cout<<-1<<"\n";
return;
}
vector<vector<pll> >vec(k+1);
int ind=1;
for(int i=1;i<=k;i++){
ll left=sum/(ll)k;
while(left>0){
if(left>=a[ind])vec[i].pb({a[ind],ind}),left-=a[ind],ind++;
else{
a[ind]-=left,vec[i].pb({left,ind});
left=0;
}
}
}
vector<int>idx(k+1,0);
vector<vector<ll> >ans(n+1);
ind=0;
while(idx[1]<vec[1].size()){
ll mn=inf;
for(int i=1;i<=k;i++){
int in=idx[i];
mn=min(mn,vec[i][in].f);
}
vector<ll>xx;
ans[ind].pb(mn);
for(int i=1;i<=k;i++){
ans[ind].pb(vec[i][idx[i]].s);
}
for(int i=1;i<=k;i++){
int in=idx[i];
vec[i][in].f-=mn;
if(vec[i][in].f==0)idx[i]++;
}
ind++;
}
cout<<ind<<"\n";
for(int i=0;i<ind;i++){
for(ll to:ans[i])cout<<to<<" ";
cout<<"\n";
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int test=1;//cin>>test;
while(test--){
solve();
}
}
컴파일 시 표준 에러 (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... |