이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
DEATH-MATCH
Davit-Marg
*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <stdlib.h>
#include <cassert>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
using namespace std;
LL gcd(LL a, LL b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
LL n, k, a[1000006], d, v, s;
bool hav = 1;
priority_queue<pair<LL, int>> q;
vector<pair<LL, int>> ans;
int main()
{
cin >> n >> k;
for (LL i = 0; i < n; i++)
{
scanf("%lld", a + i);
s += a[i];
q.push(MP(a[i], i));
if (i && a[i] != a[i - 1])
hav = 0;
}
if (hav)
{
d = k / gcd(n, k);
if (a[0] % d != 0)
{
cout << -1 << endl;
return 0;
}
cout << d * n / k;
for (LL i = 0; i < d*n; i++)
{
v %= k;
if (v == 0)
cout << endl << a[0] / d << " ";
cout << (i%n) + 1 << " ";
v++;
}
cout << endl;
}
else
{
int step = 0;
vector<pair<LL, int>> st;
while (!q.empty())
{
for (int i = 0; i < k; i++)
{
if (q.empty())
{
cout << -1 << endl;
return 0;
}
st.PB(q.top());
q.pop();
}
LL d = max(st.back().first-1ll,1ll);
/*if (!q.empty())
d = max(st.back().first - q.top().first, 1ll);*/
for (int i = k - 1; i >= 0; i--)
{
ans.PB(MP(d, st[i].second));
if (st[i].first - d > 0)
q.push(MP(st[i].first - d, st[i].second));
st.pop_back();
}
}
if (!q.empty() || !st.empty())
{
cout << -1 << endl;
return 0;
}
else
{
cout << ans.size() / k;
for (int i = 0; i < ans.size(); i++)
{
if (i%k == 0)
cout << endl << ans[i].first << " ";
cout << ans[i].second + 1 << " ";
}
cout << endl;
}
}
return 0;
}
/*
4 2
1 1 4 4
4 3
6 6 6 6
14 7
10 10 10 10 10 10 10 10 10 10 10 10 10 10
*/
컴파일 시 표준 에러 (stderr) 메시지
nicegift.cpp: In function 'int main()':
nicegift.cpp:108:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < ans.size(); i++)
~~^~~~~~~~~~~~
nicegift.cpp:74:7: warning: unused variable 'step' [-Wunused-variable]
int step = 0;
^~~~
nicegift.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", a + 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... |