Submission #347084

# Submission time Handle Problem Language Result Execution time Memory
347084 2021-01-11T17:25:01 Z andrii Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 345164 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';
        ll lcm = (n*k)/__gcd(n, k);
        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:32: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]
   32 |             if(allow.size()<k) return cout<<-1, 0;
      |                ~~~~~~~~~~~~^~
nicegift.cpp:59: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]
   59 |         if(allow.size()<k) return cout<<-1, 0;
      |            ~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 1 ms 492 KB n=8
9 Correct 9 ms 1256 KB n=14
10 Correct 5 ms 876 KB n=11
11 Correct 37 ms 6240 KB n=50000
12 Correct 63 ms 7772 KB n=50000
13 Correct 25 ms 3428 KB n=10
14 Correct 37 ms 3552 KB n=685
15 Correct 34 ms 3804 KB n=623
16 Correct 20 ms 2272 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 1 ms 492 KB n=8
9 Correct 9 ms 1256 KB n=14
10 Correct 5 ms 876 KB n=11
11 Correct 37 ms 6240 KB n=50000
12 Correct 63 ms 7772 KB n=50000
13 Correct 25 ms 3428 KB n=10
14 Correct 37 ms 3552 KB n=685
15 Correct 34 ms 3804 KB n=623
16 Correct 20 ms 2272 KB n=973
17 Correct 33 ms 2912 KB n=989
18 Correct 14 ms 1440 KB n=563
19 Correct 23 ms 1768 KB n=592
20 Correct 23 ms 1768 KB n=938
21 Correct 18 ms 1512 KB n=747
22 Correct 26 ms 1640 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 775 ms 116812 KB n=1000000
2 Correct 485 ms 65900 KB n=666666
3 Correct 268 ms 39020 KB n=400000
4 Correct 830 ms 67024 KB n=285714
5 Correct 11 ms 2540 KB n=20000
6 Correct 767 ms 55240 KB n=181818
7 Correct 6 ms 1388 KB n=10000
8 Correct 87 ms 5356 KB n=6666
9 Correct 3 ms 748 KB n=4000
10 Correct 487 ms 25836 KB n=2857
11 Correct 2 ms 620 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 0 ms 364 KB n=5
8 Correct 1 ms 492 KB n=8
9 Correct 9 ms 1256 KB n=14
10 Correct 5 ms 876 KB n=11
11 Correct 37 ms 6240 KB n=50000
12 Correct 63 ms 7772 KB n=50000
13 Correct 25 ms 3428 KB n=10
14 Correct 37 ms 3552 KB n=685
15 Correct 34 ms 3804 KB n=623
16 Correct 20 ms 2272 KB n=973
17 Correct 33 ms 2912 KB n=989
18 Correct 14 ms 1440 KB n=563
19 Correct 23 ms 1768 KB n=592
20 Correct 23 ms 1768 KB n=938
21 Correct 18 ms 1512 KB n=747
22 Correct 26 ms 1640 KB n=991
23 Correct 775 ms 116812 KB n=1000000
24 Correct 485 ms 65900 KB n=666666
25 Correct 268 ms 39020 KB n=400000
26 Correct 830 ms 67024 KB n=285714
27 Correct 11 ms 2540 KB n=20000
28 Correct 767 ms 55240 KB n=181818
29 Correct 6 ms 1388 KB n=10000
30 Correct 87 ms 5356 KB n=6666
31 Correct 3 ms 748 KB n=4000
32 Correct 487 ms 25836 KB n=2857
33 Correct 2 ms 620 KB n=2000
34 Execution timed out 2115 ms 345164 KB Time limit exceeded
35 Halted 0 ms 0 KB -