Submission #90939

# Submission time Handle Problem Language Result Execution time Memory
90939 2018-12-25T09:05:56 Z toloraia Gift (IZhO18_nicegift) C++17
30 / 100
987 ms 77572 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 = 1e9 + 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;
        if (n * m > 3e6){
            assert(0);
            return 0;
        }
        cout<<n / d<<endl;
        for (ll i = 1; i <= n; i += d){
            cout<<p<<" ";
            for (ll j = i; j < i + d; j++)
                cout<<(j - 1) % n + 1<<" ";
            cout<<endl;
        }
        return 0;
    }
        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);
            }
            v.clear();
            for (ll i = 1; i < I1; i++){
                v.pb (P[i].S);
                P[i].F--;
            }
            for (ll i = I2; (ll)v.size() < k; i--){
                v.pb (P[i].S);
                P[i].F--;
            }
            V[++nn] = v;
        }
        if (P[1].F > 0){
            cout<<-1<<endl;
            return 0;
        }
        cout<<nn<<endl;
        for (ll i = 1; i <= nn; i++){
            cout<<"1 ";
            for (ll j = 0; 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 47328 KB n=4
2 Correct 45 ms 47348 KB n=3
3 Correct 43 ms 47348 KB n=3
4 Correct 43 ms 47384 KB n=4
5 Correct 42 ms 47436 KB n=4
6 Correct 43 ms 47452 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47328 KB n=4
2 Correct 45 ms 47348 KB n=3
3 Correct 43 ms 47348 KB n=3
4 Correct 43 ms 47384 KB n=4
5 Correct 42 ms 47436 KB n=4
6 Correct 43 ms 47452 KB n=2
7 Correct 43 ms 47500 KB n=5
8 Correct 45 ms 47840 KB n=8
9 Correct 65 ms 48036 KB n=14
10 Correct 57 ms 48036 KB n=11
11 Correct 129 ms 50696 KB n=50000
12 Correct 132 ms 50804 KB n=50000
13 Correct 119 ms 50804 KB n=10
14 Correct 112 ms 50804 KB n=685
15 Correct 115 ms 50804 KB n=623
16 Correct 82 ms 50804 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47328 KB n=4
2 Correct 45 ms 47348 KB n=3
3 Correct 43 ms 47348 KB n=3
4 Correct 43 ms 47384 KB n=4
5 Correct 42 ms 47436 KB n=4
6 Correct 43 ms 47452 KB n=2
7 Correct 43 ms 47500 KB n=5
8 Correct 45 ms 47840 KB n=8
9 Correct 65 ms 48036 KB n=14
10 Correct 57 ms 48036 KB n=11
11 Correct 129 ms 50696 KB n=50000
12 Correct 132 ms 50804 KB n=50000
13 Correct 119 ms 50804 KB n=10
14 Correct 112 ms 50804 KB n=685
15 Correct 115 ms 50804 KB n=623
16 Correct 82 ms 50804 KB n=973
17 Correct 91 ms 50804 KB n=989
18 Correct 59 ms 50804 KB n=563
19 Correct 59 ms 50804 KB n=592
20 Correct 60 ms 50804 KB n=938
21 Correct 60 ms 50804 KB n=747
22 Correct 58 ms 50804 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 987 ms 77572 KB n=1000000
2 Correct 530 ms 77572 KB n=666666
3 Correct 266 ms 77572 KB n=400000
4 Incorrect 497 ms 77572 KB Expected int32, but "500000500000" found
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 44 ms 47328 KB n=4
2 Correct 45 ms 47348 KB n=3
3 Correct 43 ms 47348 KB n=3
4 Correct 43 ms 47384 KB n=4
5 Correct 42 ms 47436 KB n=4
6 Correct 43 ms 47452 KB n=2
7 Correct 43 ms 47500 KB n=5
8 Correct 45 ms 47840 KB n=8
9 Correct 65 ms 48036 KB n=14
10 Correct 57 ms 48036 KB n=11
11 Correct 129 ms 50696 KB n=50000
12 Correct 132 ms 50804 KB n=50000
13 Correct 119 ms 50804 KB n=10
14 Correct 112 ms 50804 KB n=685
15 Correct 115 ms 50804 KB n=623
16 Correct 82 ms 50804 KB n=973
17 Correct 91 ms 50804 KB n=989
18 Correct 59 ms 50804 KB n=563
19 Correct 59 ms 50804 KB n=592
20 Correct 60 ms 50804 KB n=938
21 Correct 60 ms 50804 KB n=747
22 Correct 58 ms 50804 KB n=991
23 Correct 987 ms 77572 KB n=1000000
24 Correct 530 ms 77572 KB n=666666
25 Correct 266 ms 77572 KB n=400000
26 Incorrect 497 ms 77572 KB Expected int32, but "500000500000" found
27 Halted 0 ms 0 KB -