답안 #726674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726674 2023-04-19T08:54:51 Z fdnfksd Gift (IZhO18_nicegift) C++14
49 / 100
265 ms 23752 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,k,a[maxN];
void solve()
{
    cin >> n >> k;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        sum+=a[i];
    }
    if(sum<=1e5)
    {
        priority_queue<pli> pq;
        for(int i=1;i<=n;i++) pq.push({a[i],i});
        vector<pli> vc;
        vc.resize(k);
        vector<vector<ll>> ans;
        while(pq.size()>=k)
        {
            vector<ll> vd;
            vd.pb(1);
            for(int i=0;i<k;i++)
            {
                vc[i]=pq.top();
                pq.pop();
                vc[i].fi--;
                vd.pb(vc[i].se);
            }
            sum-=k;
            ans.pb(vd);
            for(int i=0;i<k;i++)
            {
                if(vc[i].fi>0) pq.push(vc[i]);
            }
        }
        if(sum==0)
        {
            cout << ans.size()<<'\n';
            for(auto vec:ans)
            {
                for(auto zz:vec) cout << zz<<' ';
                cout << '\n';
            }
        }
        else cout << -1;
    }
    else
    {
        for(int i=1;i<n;i++)
        {
            if(a[i]!=a[i+1])
            {
                cout << -1;
                return;
            }
        }
        if(a[1]*n%k!=0) cout << -1;
        else
        {
            ll x=-1,y=-1;
            for(ll i=1;i<=k;i++)
            {
                if(k%i==0&&n%i==0&&a[1]%(k/i)==0)
                {
                    x=i;
                    y=k/i;
                }
            }
            if(x==-1) {cout << -1;return;}
            ll s=1;
            cout << n/x<<'\n';
            for(int i=1;i<=n/x;i++)
            {
                cout << a[1]/y<<' ';
                ll cnt=k;
                while(cnt--)
                {
                    cout << s<<' ';
                    s=s+1;
                    if(s>n) s-=n;
                }
                cout << '\n';
            }
        }
    }
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

nicegift.cpp: In function 'void solve()':
nicegift.cpp:30:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   30 |         while(pq.size()>=k)
      |               ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 3 ms 980 KB n=8
9 Correct 7 ms 1168 KB n=14
10 Correct 4 ms 980 KB n=11
11 Correct 32 ms 4512 KB n=50000
12 Correct 31 ms 4464 KB n=50000
13 Correct 22 ms 3464 KB n=10
14 Correct 24 ms 3064 KB n=685
15 Correct 26 ms 3344 KB n=623
16 Correct 15 ms 1932 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 3 ms 980 KB n=8
9 Correct 7 ms 1168 KB n=14
10 Correct 4 ms 980 KB n=11
11 Correct 32 ms 4512 KB n=50000
12 Correct 31 ms 4464 KB n=50000
13 Correct 22 ms 3464 KB n=10
14 Correct 24 ms 3064 KB n=685
15 Correct 26 ms 3344 KB n=623
16 Correct 15 ms 1932 KB n=973
17 Correct 23 ms 2956 KB n=989
18 Correct 10 ms 1236 KB n=563
19 Correct 17 ms 1704 KB n=592
20 Correct 17 ms 1748 KB n=938
21 Correct 13 ms 1352 KB n=747
22 Correct 15 ms 1492 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 22724 KB n=1000000
2 Correct 166 ms 22660 KB n=666666
3 Correct 98 ms 12800 KB n=400000
4 Correct 199 ms 23752 KB n=285714
5 Correct 5 ms 852 KB n=20000
6 Correct 175 ms 19568 KB n=181818
7 Correct 3 ms 596 KB n=10000
8 Correct 23 ms 1996 KB n=6666
9 Correct 1 ms 340 KB n=4000
10 Correct 123 ms 9660 KB n=2857
11 Correct 1 ms 340 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n=4
2 Correct 0 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 3 ms 980 KB n=8
9 Correct 7 ms 1168 KB n=14
10 Correct 4 ms 980 KB n=11
11 Correct 32 ms 4512 KB n=50000
12 Correct 31 ms 4464 KB n=50000
13 Correct 22 ms 3464 KB n=10
14 Correct 24 ms 3064 KB n=685
15 Correct 26 ms 3344 KB n=623
16 Correct 15 ms 1932 KB n=973
17 Correct 23 ms 2956 KB n=989
18 Correct 10 ms 1236 KB n=563
19 Correct 17 ms 1704 KB n=592
20 Correct 17 ms 1748 KB n=938
21 Correct 13 ms 1352 KB n=747
22 Correct 15 ms 1492 KB n=991
23 Correct 265 ms 22724 KB n=1000000
24 Correct 166 ms 22660 KB n=666666
25 Correct 98 ms 12800 KB n=400000
26 Correct 199 ms 23752 KB n=285714
27 Correct 5 ms 852 KB n=20000
28 Correct 175 ms 19568 KB n=181818
29 Correct 3 ms 596 KB n=10000
30 Correct 23 ms 1996 KB n=6666
31 Correct 1 ms 340 KB n=4000
32 Correct 123 ms 9660 KB n=2857
33 Correct 1 ms 340 KB n=2000
34 Incorrect 3 ms 576 KB Jury has the answer but participant has not
35 Halted 0 ms 0 KB -