# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
516336 | fcmalkcin | Gift (IZhO18_nicegift) | C++17 | 728 ms | 228884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define F(i,a,b) for (ll i=a;i<=b;i++)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=4e6+40;
const ll mod=1000003 ;
const ll base=3e18;
/// you will be the best but now you just are trash
/// goal 2/7
ll n, k;
pll a[maxn];
vector<pll> gr[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll n, k;
cin>> n>> k;
ll cnt=0;
for (int i=1;i<=n;i++)
{
cin>> a[i].ff;
cnt+=a[i].ff;
a[i].ss=i;
}
sort(a+1,a+n+1);
if (cnt%k!=0)
{
cout <<-1;
return 0;
}
if (a[n].ff>(cnt/k))
{
cout <<-1;
return 0;
}
cnt/=k;
pll pre=make_pair(0,0);
ll dem=0;
// cout <<cnt<<endl;
for (int i=1;i<=n;i++)
{
dem++;
ll j=i;
ll nw=a[i].ff+pre.ff;
if(pre.ss) gr[dem].pb(pre);
gr[dem].pb(a[i]);
// cout <<i<<" "<<nw<<" "<<pre.ff<<" "<<pre.ss<<endl;
while (nw<cnt)
{
j++,nw+=a[j].ff;
if (nw<=cnt) gr[dem].pb(a[j]);
else gr[dem].pb(make_pair(a[j].ff-(nw-cnt),a[j].ss));
}
// assert(nw>=cnt);
if (nw>cnt)
{
// assert(a[j].ff>nw-cnt);
pre=make_pair(nw-cnt,a[j].ss);
}
else
{
pre=make_pair(0,0);
}
i=j;
}
// cout <<dem<<endl;
/* for (int i=1;i<=k;i++)
{
for (auto to:gr[i]) cout <<to.ff<<" "<<to.ss<<" ";
cout <<endl;
}*/
vector<pair<ll,vector<ll>>> ans;
while (1)
{
bool kt=true;
ll val1=base;
for (int i=1;i<=k;i++)
{
if (!gr[i].size())
{
kt=false;
break;
}
else
{
val1=min(val1,gr[i].back().ff);
}
}
if (kt)
{
// assert(val1);
vector<ll> vt;
for (int i=1;i<=k;i++)
{
if (gr[i].back().ff==val1)
{
vt.pb(gr[i].back().ss);
gr[i].pop_back();
}
else
{
gr[i][gr[i].size()-1].ff-=val1;
vt.pb(gr[i].back().ss);
}
}
ans.pb(make_pair(val1,vt));
}
else
{
break;
}
}
cout <<ans.size()<<endl;
for (auto to:ans)
{
cout <<to.ff<<" ";
for (auto p:to.ss) cout <<p<<" ";
cout <<endl;
}
}
컴파일 시 표준 에러 (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... |