# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
511100 | Mazaalai | Gift (IZhO18_nicegift) | C++17 | 3 ms | 588 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LLA(x) x.rbegin(),x.rend()
#define print(x) for(auto el:x)cout<<el<<' ';cout<<"\n";
#define printPII(x) for(auto [a,b]:x)cout<<a<<","<<b<<' ';cout<<'\n';
using namespace std;
using ll = long long;
using PII = pair <ll, ll>;
ll n, k, onePick = 1;
bool impossible;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
cin >> n >> k;
vector <vector <ll> > ans;
set <PII> bfs;
ll sum = 0;
vector <ll> vals, vals1;
for (int i = 1; i <= n; i++) {
ll x; cin >> x;
sum += x;
vals.pb(x);
bfs.insert({x, i});
}
sort(LLA(vals));
if (sum % k != 0) {
cout << "-1\n";
return 0;
}
if (vals[0] == vals.back()) {
ll cycleLen = k * n / gcd(k, n); // 4, 6, 2-> 12
ll oneCycleContribution = cycleLen / n; //
onePick = vals[0] / oneCycleContribution;
for (auto& el : vals) el /= onePick;
sum /= onePick;
}
while(!impossible && sum > 0) {
vector <ll> pick(1, onePick);
vector <PII> add;
for (int i = 0; i < k; i++) {
auto it = --bfs.end();
PII cur = *it;
bfs.erase(it);
pick.pb(cur.ss);
cur.ff--;
sum--;
if (cur.ff < 0) {
impossible = 1;
break;
}
add.pb(cur);
}
ans.pb(pick);
for (auto el : add) bfs.insert(el);
}
// int dbg = 0;
if (impossible) {
cout << "-1\n";
return 0;
}
cout << ans.size() << '\n';
for (auto el : ans) {
print(el);
}
}
컴파일 시 표준 에러 (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... |