이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz size()
#define mk make_pair
#define ff first
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define ss second
#define all(x) x.begin(), x.end()
#define Resh cin>>tt;while(tt--)solve();
#define yes cout <<"Yes"<<"\n";
#define no cout <<"No"<<"\n";
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define left(v) v + v
#define right(v) v + v + 1
const long double PI = acos(-1);
const long long n6 = 1e6 + 10;
const long long n5 = 1e5+1;
const long long n4 = 1e4 + 10;
const long long inf = 1e9;
const long long mod = 16714589;
const int BL = 60090;
const long long MAXN = 1e5+5;
ll a[n5];
multiset<pll> ms;
vector<vector<pll>> ans;
main() {
fast
ll n, k, cnt=0;
cin >> n >> k;
for(int i = 1;i <= n;i++) {
cin >> a[i];
cnt+=a[i];
}
if(cnt % k) {
cout << -1;
return 0;
}
for(int i = 1;i <= n;i++) {
ms.insert(mk(a[i], i));
}
while(ms.sz >= k) {
vector<pll> v;
while(v.sz < k) {
pll p = *ms.rbegin();
p.ff--;
v.pb(p);
ms.erase(--ms.end());
}
for(auto c : v) {
if(c.ff) {
ms.insert(c);
}
}
ans.pb(v);
}
cout << ans.size() <<'\n';
for(auto c : ans) {
cout << "1 ";
for(auto t : c) {
cout << t.ss << " ";
}
cout <<'\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
nicegift.cpp:1: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
1 | #pragma comment(linker, "/stack:200000000")
|
nicegift.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main() {
| ^~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:49:17: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
49 | while(ms.sz >= k) {
| ~~~~~~^~~~
nicegift.cpp:51:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
51 | while(v.sz < k) {
| ~~~~~^~~
# | 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... |