답안 #347083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
347083 2021-01-11T17:20:23 Z andrii Gift (IZhO18_nicegift) C++14
30 / 100
2000 ms 283596 KB
// -- //
#include <bits/stdc++.h>
#define pll pair<ll, ll>
#define x first
#define y second
using namespace std;
typedef long long ll;
const ll N = 1e6+228;
const ll inf = 0x3fff3fff3fff3fff;
pll a[N];
vector<pair<ll, vector<ll>>> qrs;
ll us[N];
signed main(){
	cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n, k, sai=0;
    cin >> n >> k;
    for(ll i = 0;i<n;i++){
        cin >> a[i].x;
        a[i].y=i;
        sai+=a[i].x;
    }
    sort(a, a+n, greater<pll>());
    if(a[0].x==a[n-1].x){
        cout<<qrs.size()<<'\n';
        for(auto i :qrs){
            cout<<i.x<<' ';
            for(auto j : i.y) cout<<a[j].y+1<<' ';
            cout<<'\n';
        }
        ll lcm = sai/__gcd(n, a[0].x);
        ll c = lcm/n;
        ll tt = sai/(c*n);
        for(ll i = 0;i<n;i++) a[i].x/=tt;
        set<pll, greater<pll>> allow;
        for(ll i = 0;i<n;i++) allow.insert({a[i].x, i});
        for(;!allow.empty();){
            if(allow.size()<k) return cout<<-1, 0;
            vector<ll> qk;
            ll mv= inf;
            for(ll i = 0;i<k;i++){
                qk.push_back(allow.begin()->second);
                mv=allow.begin()->first;
                allow.erase(allow.begin());
            }
            mv=1;
            for(auto i : qk){
                us[i]+=mv;
                if(us[i]<a[i].x) allow.insert({a[i].x-us[i], i});
            }
            qrs.push_back({mv, qk});
        }
        cout<<qrs.size()<<'\n';
        for(auto i :qrs){
            cout<<tt<<' ';
            for(auto j : i.y) cout<<a[j].y+1<<' ';
            cout<<'\n';
        }
        return 0;
    }
    if(sai%k) return cout<<-1, 0;
    set<pll, greater<pll>> allow;
    for(ll i = 0;i<n;i++) allow.insert({a[i].x, i});
    for(;!allow.empty();){
        if(allow.size()<k) return cout<<-1, 0;
        vector<ll> qk;
        ll mv= inf;
        for(ll i = 0;i<k;i++){
            qk.push_back(allow.begin()->second);
            mv=allow.begin()->first;
            allow.erase(allow.begin());
        }
        if(!allow.empty()) mv=mv-allow.begin()->first;
        mv=max(mv, 1ll);
        for(auto i : qk){
            us[i]+=mv;
            if(us[i]<a[i].x) allow.insert({a[i].x-us[i], i});
        }
        qrs.push_back({mv, qk});
    }
    cout<<qrs.size()<<'\n';
    for(auto i :qrs){
        cout<<i.x<<' ';
        for(auto j : i.y) cout<<a[j].y+1<<' ';
        cout<<'\n';
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:37:28: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   37 |             if(allow.size()<k) return cout<<-1, 0;
      |                ~~~~~~~~~~~~^~
nicegift.cpp:64:24: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int>, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   64 |         if(allow.size()<k) return cout<<-1, 0;
      |            ~~~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 492 KB n=8
9 Correct 9 ms 1256 KB n=14
10 Correct 6 ms 876 KB n=11
11 Correct 38 ms 6368 KB n=50000
12 Correct 52 ms 7772 KB n=50000
13 Correct 26 ms 3576 KB n=10
14 Correct 31 ms 3552 KB n=685
15 Correct 34 ms 3804 KB n=623
16 Correct 19 ms 2272 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 492 KB n=8
9 Correct 9 ms 1256 KB n=14
10 Correct 6 ms 876 KB n=11
11 Correct 38 ms 6368 KB n=50000
12 Correct 52 ms 7772 KB n=50000
13 Correct 26 ms 3576 KB n=10
14 Correct 31 ms 3552 KB n=685
15 Correct 34 ms 3804 KB n=623
16 Correct 19 ms 2272 KB n=973
17 Correct 32 ms 2840 KB n=989
18 Correct 15 ms 1384 KB n=563
19 Correct 23 ms 1768 KB n=592
20 Correct 24 ms 1776 KB n=938
21 Correct 18 ms 1512 KB n=747
22 Correct 20 ms 1640 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2093 ms 283596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 384 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 492 KB n=8
9 Correct 9 ms 1256 KB n=14
10 Correct 6 ms 876 KB n=11
11 Correct 38 ms 6368 KB n=50000
12 Correct 52 ms 7772 KB n=50000
13 Correct 26 ms 3576 KB n=10
14 Correct 31 ms 3552 KB n=685
15 Correct 34 ms 3804 KB n=623
16 Correct 19 ms 2272 KB n=973
17 Correct 32 ms 2840 KB n=989
18 Correct 15 ms 1384 KB n=563
19 Correct 23 ms 1768 KB n=592
20 Correct 24 ms 1776 KB n=938
21 Correct 18 ms 1512 KB n=747
22 Correct 20 ms 1640 KB n=991
23 Execution timed out 2093 ms 283596 KB Time limit exceeded
24 Halted 0 ms 0 KB -