Submission #90945

# Submission time Handle Problem Language Result Execution time Memory
90945 2018-12-25T09:15:31 Z toloraia Gift (IZhO18_nicegift) C++14
26 / 100
989 ms 77400 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const ll N = 2e6 + 5, INF = 2e18 + 5;

ll n, k;
pair < ll, ll > P[N];
ll nn;
vector < ll > V[N], v;

main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for (ll i = 1; i <= n; i++){
        cin>>P[i].F;
        P[i].S = i;
    }
    sort (P + 1, P + n + 1);
    reverse (P + 1, P + n + 1);
    if (P[1].F == P[n].F){
        ll d = __gcd (n, k);
        ll m = k / d;
        if (P[1].F % m != 0){
            cout<<-1<<endl;
            return 0;
        }
        ll p = P[1].F / m;
        cout<<n / d<<endl;
        for (ll i = 1; i <= n; i += d){
            cout<<p<<" ";
            for (ll j = i; j < i + k; j++)
                cout<<(j - 1) % n + 1<<" ";
            cout<<endl;
        }
        return 0;
    }
    P[0].F = INF;
        while (P[k].F > 0){
            ll I1 = k, I2 = k;
            for (ll i = 20; i >= 0; i--){
                if (I1 - (1<<i) <= 0)
                    continue;
                if (P[I1 - (1<<i)].F == P[k].F)
                    I1 -= (1<<i);
            }
            for (ll i = 20; i >= 0; i--){
                if (I2 + (1<<i) > n)
                    continue;
                if (P[I2 + (1<<i)].F == P[k].F)
                    I2 += (1<<i);
            }
            ll x = min (P[I1 - 1].F - P[I1].F, P[I2].F - P[I2 + 1].F);
            v.clear();
            v.pb(x);
            for (ll i = 1; i < I1; i++){
                v.pb (P[i].S);
                P[i].F-=x;
            }
            for (ll i = I2; (ll)v.size() <= k; i--){
                v.pb (P[i].S);
                P[i].F-=x;
            }
            V[++nn] = v;
        }
        if (P[1].F > 0){
            cout<<-1<<endl;
            return 0;
        }
        cout<<nn<<endl;
        for (ll i = 1; i <= nn; i++){
            cout<<V[i][0]<<" ";
            for (ll j = 1; j <= k; j++)
                cout<<V[i][j]<<" ";
            cout<<endl;
        }
    return 0;
}

Compilation message

nicegift.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 45 ms 47580 KB n=3
3 Correct 45 ms 47580 KB n=3
4 Correct 37 ms 47612 KB n=4
5 Correct 39 ms 47612 KB n=4
6 Correct 43 ms 47612 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 45 ms 47580 KB n=3
3 Correct 45 ms 47580 KB n=3
4 Correct 37 ms 47612 KB n=4
5 Correct 39 ms 47612 KB n=4
6 Correct 43 ms 47612 KB n=2
7 Correct 38 ms 47612 KB n=5
8 Correct 39 ms 47612 KB n=8
9 Correct 39 ms 47612 KB n=14
10 Correct 38 ms 47612 KB n=11
11 Correct 120 ms 49712 KB n=50000
12 Correct 87 ms 49712 KB n=50000
13 Correct 37 ms 49712 KB n=10
14 Incorrect 39 ms 49712 KB Jury has the answer but participant has not
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 45 ms 47580 KB n=3
3 Correct 45 ms 47580 KB n=3
4 Correct 37 ms 47612 KB n=4
5 Correct 39 ms 47612 KB n=4
6 Correct 43 ms 47612 KB n=2
7 Correct 38 ms 47612 KB n=5
8 Correct 39 ms 47612 KB n=8
9 Correct 39 ms 47612 KB n=14
10 Correct 38 ms 47612 KB n=11
11 Correct 120 ms 49712 KB n=50000
12 Correct 87 ms 49712 KB n=50000
13 Correct 37 ms 49712 KB n=10
14 Incorrect 39 ms 49712 KB Jury has the answer but participant has not
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 989 ms 77400 KB n=1000000
2 Correct 538 ms 77400 KB n=666666
3 Correct 262 ms 77400 KB n=400000
4 Correct 651 ms 77400 KB n=285714
5 Correct 52 ms 77400 KB n=20000
6 Correct 479 ms 77400 KB n=181818
7 Correct 48 ms 77400 KB n=10000
8 Correct 66 ms 77400 KB n=6666
9 Correct 47 ms 77400 KB n=4000
10 Correct 200 ms 77400 KB n=2857
11 Correct 39 ms 77400 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47352 KB n=4
2 Correct 45 ms 47580 KB n=3
3 Correct 45 ms 47580 KB n=3
4 Correct 37 ms 47612 KB n=4
5 Correct 39 ms 47612 KB n=4
6 Correct 43 ms 47612 KB n=2
7 Correct 38 ms 47612 KB n=5
8 Correct 39 ms 47612 KB n=8
9 Correct 39 ms 47612 KB n=14
10 Correct 38 ms 47612 KB n=11
11 Correct 120 ms 49712 KB n=50000
12 Correct 87 ms 49712 KB n=50000
13 Correct 37 ms 49712 KB n=10
14 Incorrect 39 ms 49712 KB Jury has the answer but participant has not
15 Halted 0 ms 0 KB -