답안 #137458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137458 2019-07-27T19:24:22 Z vardan__02 Gift (IZhO18_nicegift) C++14
19 / 100
1696 ms 25600 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
ll n,k,a[1000005],m,i,j,p,q,t,u,v;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]!=a[1])
            t=1;
    }
    if(t==0)
    {
        if(n%k!=0)
        {
            if(a[1]%k!=0)
            {
                if(n*a[1]%k!=0)
                    cout<<-1<<endl;
                else
                {
                    p=k+n%k;
                    if(a[n]>k)
                    m=n/k-1+p+p/2;
                    else
                    m=n/k-1+p/2;
                    cout<<m<<endl;
                    v=a[n]/k;
                    if(a[n]>k)
                    {
                        for(i=1;i<=p;i++)
                        {
                            cout<<v<<" ";
                            q=k;
                            u=a[p];
                            j=1;
                            while(a[j]!=u)
                                j++;
                            while(j<=p && q!=0)
                            {
                                a[j]-=v;
                                cout<<j<<" ";
                                j++;
                                q--;
                            }
                            if(q!=0)
                            {
                                u=a[p];
                                j=1;
                                while(a[j]!=u)
                                    j++;
                                while(q!=0 && j<=p)
                                {
                                    a[j]-=v;
                                    cout<<j<<" ";
                                    j++;
                                    q--;
                                }
                            }
                            cout<<endl;
                        }
                    }
                    for(i=1;i<=p/2;i++)
                    {
                        cout<<1<<" ";
                        q=k;
                        u=a[p];
                        j=1;
                        while(a[j]!=u)
                            j++;
                        while(j<=p && q!=0)
                        {
                            a[j]--;
                            cout<<j<<" ";
                            j++;
                            q--;
                        }
                        if(q!=0)
                        {
                            u=a[p];
                            j=1;
                            while(a[j]!=u)
                                j++;
                            while(q!=0 && j<=p)
                            {
                                a[j]--;
                                cout<<j<<" ";
                                j++;
                                q--;
                            }
                        }
                        cout<<endl;
                    }
                    for(i=p+1;i<=n;i++)
                    {
                        if((i-p)%k==1)
                            cout<<a[n]<<" ";
                        cout<<i<<" ";
                        if((i-p)%k==0)
                            cout<<endl;
                    }
                }
            }
            else
            {
                p=k+n%k;
                m=n/k-1+p;
                cout<<m<<endl;
                v=a[n]/k;
                for(i=1;i<=p;i++)
                {
                    cout<<v<<" ";
                    q=k;
                    u=a[p];
                    j=1;
                    while(a[j]!=u)
                        j++;
                    while(j<=p && q!=0)
                    {
                        a[j]-=v;
                        cout<<j<<" ";
                        j++;
                        q--;
                    }
                    if(q!=0)
                    {
                        u=a[p];
                        j=1;
                        while(a[j]!=u)
                            j++;
                        while(q!=0 && j<=p)
                        {
                            a[j]-=v;
                            cout<<j<<" ";
                            j++;
                            q--;
                        }
                    }
                    cout<<endl;
                }
                for(i=p+1;i<=n;i++)
                {
                    if((i-p)%k==1)
                        cout<<a[n]<<" ";
                    cout<<i<<" ";
                    if((i-p)%k==0)
                        cout<<endl;
                }
            }
        }
        else
        {
            cout<<n/k<<endl;
            cout<<a[1]<<" ";
            for(i=1;i<=n;i++)
            {
                cout<<i<<" ";
                if(i%k==0)
                {
                    cout<<endl;
                    if(i!=n)
                        cout<<a[1]<<" ";
                }
            }
        }
    }
    else
    {

    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1696 ms 25600 KB n=1000000
2 Correct 824 ms 16632 KB n=666666
3 Correct 347 ms 10488 KB n=400000
4 Correct 206 ms 8240 KB n=285714
5 Correct 9 ms 888 KB n=20000
6 Correct 105 ms 5624 KB n=181818
7 Correct 5 ms 632 KB n=10000
8 Correct 19 ms 1144 KB n=6666
9 Correct 3 ms 508 KB n=4000
10 Correct 47 ms 2680 KB n=2857
11 Correct 3 ms 376 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -