이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 1000005
#define pii pair<int, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
inline void rint(ll &x) {
x = 0;
char c;
do {
c = getchar();
} while (c < '0' || c > '9');
do {
x = (x<<3) + (x<<1) + (c - '0');
c = getchar();
} while (c >= '0' && c <= '9');
}
inline void pint(int x) {
while (x) {
putchar('0' + x % 10);
x /= 10;
}
putchar(' ');
}
ll a[maxn], pref[maxn];
vector<ll> val;
vector<int> ans[maxn];
int main() {
io
ll n, k;
rint(n), rint(k);
ll m = 0;
for (int i = 0;i < n;i++) {
rint(a[i]);
m += a[i];
pref[i] = m;
}
bool poss = m % k == 0;
ll siz = m / k;
for (int i = 0;i < n;i++) {
if (a[i] > siz) {
poss = false;
break;
}
val.push_back(pref[i] % siz);
}
sort(val.begin(), val.end());
val.push_back(siz);
val.resize(int(unique(val.begin(), val.end()) - val.begin()));
if (!poss) {
cout << -1 << endl;
} else {
int num = 0, ind = 0;
ll cur = 0;
for (int i = 0;i < val.size();i++) {
//cout << val[i] << " " << cur << endl;
if (val[i] - cur > 0) { //[cur, val[i])
ans[num].push_back(val[i] - cur);
while (ind < n && pref[ind] <= cur) ind++;
int id = ind;
for (ll j = cur;j < m;j += siz) {
while (id < n && pref[id] <= j) id++;
if (id < n) ans[num].push_back(id+1);
else {
break;
}
}
cur = val[i];
num++;
}
}
pint(num);
putchar('\n');
for (int i = 0;i < num;i++) {
for (int j:ans[i]) pint(j);
putchar('\n');
}
}
}
/*
4 2
2 3 3 2
6 4
4 1 3 5 5 2
*/
컴파일 시 표준 에러 (stderr) 메시지
nicegift.cpp: In function 'int main()':
nicegift.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i = 0;i < val.size();i++) {
| ~~^~~~~~~~~~~~
# | 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... |