Submission #860858

# Submission time Handle Problem Language Result Execution time Memory
860858 2023-10-14T16:18:37 Z alexdd Gift (IZhO18_nicegift) C++17
30 / 100
238 ms 39004 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
int a[1000005];
priority_queue<pair<int,int>> pq;
vector<vector<int>> af;
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>k;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum += a[i];
        pq.push({a[i],i});
    }
    if(sum%k!=0)
    {
        cout<<-1;
        return 0;
    }
    if(sum<=1000000)
    {
        while(!pq.empty())
        {
            if((int)pq.size()<k)
            {
                cout<<-1;
                return 0;
            }
            vector<int> sc;
            //cout<<1<<" ";
            for(int i=0;i<k;i++)
            {
                sc.push_back(pq.top().second);
                a[sc.back()]--;
                //cout<<sc.back()<<" ";
                pq.pop();
            }
            //cout<<"\n";
            for(auto x:sc)
                if(a[x]>0)
                    pq.push({a[x],x});
            af.push_back(sc);
        }
        cout<<af.size()<<"\n";
        for(int i=0;i<(int)af.size();i++)
        {
            cout<<1<<" ";
            for(int j=0;j<af[i].size();j++)
                cout<<af[i][j]<<" ";
            cout<<"\n";
        }
    }
    else
    {
        if(n%k==0)
        {
            cout<<n/k<<"\n";
            for(int i=1;i<=n;i+=k)
            {
                cout<<a[1]<<" ";
                for(int j=i;j<i+k;j++)
                    cout<<j<<" ";
                cout<<"\n";
            }
        }
        else if(a[1]%k==0)
        {
            cout<<n<<"\n";
            for(int i=1;i<=n;i++)
            {
                cout<<a[1]/k<<" ";
                for(int j=0;j<k;j++)
                    cout<<(i-1+j)%n + 1<<" ";
                cout<<"\n";
            }
        }
        else
        {
            cout<<-1;
        }
    }
    return 0;
}
/**
4 2
2 3 3 2
*/

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:52:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for(int j=0;j<af[i].size();j++)
      |                         ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 344 KB n=5
8 Correct 2 ms 1116 KB n=8
9 Correct 5 ms 1172 KB n=14
10 Correct 3 ms 1116 KB n=11
11 Correct 24 ms 6848 KB n=50000
12 Correct 24 ms 6868 KB n=50000
13 Correct 16 ms 3600 KB n=10
14 Correct 19 ms 3112 KB n=685
15 Correct 20 ms 3344 KB n=623
16 Correct 11 ms 1968 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 344 KB n=5
8 Correct 2 ms 1116 KB n=8
9 Correct 5 ms 1172 KB n=14
10 Correct 3 ms 1116 KB n=11
11 Correct 24 ms 6848 KB n=50000
12 Correct 24 ms 6868 KB n=50000
13 Correct 16 ms 3600 KB n=10
14 Correct 19 ms 3112 KB n=685
15 Correct 20 ms 3344 KB n=623
16 Correct 11 ms 1968 KB n=973
17 Correct 20 ms 2580 KB n=989
18 Correct 9 ms 1368 KB n=563
19 Correct 14 ms 1624 KB n=592
20 Correct 15 ms 1628 KB n=938
21 Correct 11 ms 1368 KB n=747
22 Correct 13 ms 1628 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 238 ms 39004 KB n=1000000
2 Correct 148 ms 25392 KB n=666666
3 Correct 81 ms 15288 KB n=400000
4 Correct 168 ms 26696 KB n=285714
5 Correct 5 ms 1500 KB n=20000
6 Correct 144 ms 24692 KB n=181818
7 Correct 2 ms 992 KB n=10000
8 Incorrect 1 ms 600 KB Jury has the answer but participant has not
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 1 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 344 KB n=5
8 Correct 2 ms 1116 KB n=8
9 Correct 5 ms 1172 KB n=14
10 Correct 3 ms 1116 KB n=11
11 Correct 24 ms 6848 KB n=50000
12 Correct 24 ms 6868 KB n=50000
13 Correct 16 ms 3600 KB n=10
14 Correct 19 ms 3112 KB n=685
15 Correct 20 ms 3344 KB n=623
16 Correct 11 ms 1968 KB n=973
17 Correct 20 ms 2580 KB n=989
18 Correct 9 ms 1368 KB n=563
19 Correct 14 ms 1624 KB n=592
20 Correct 15 ms 1628 KB n=938
21 Correct 11 ms 1368 KB n=747
22 Correct 13 ms 1628 KB n=991
23 Correct 238 ms 39004 KB n=1000000
24 Correct 148 ms 25392 KB n=666666
25 Correct 81 ms 15288 KB n=400000
26 Correct 168 ms 26696 KB n=285714
27 Correct 5 ms 1500 KB n=20000
28 Correct 144 ms 24692 KB n=181818
29 Correct 2 ms 992 KB n=10000
30 Incorrect 1 ms 600 KB Jury has the answer but participant has not
31 Halted 0 ms 0 KB -