Submission #516270

# Submission time Handle Problem Language Result Execution time Memory
516270 2022-01-21T01:06:56 Z fcmalkcin Gift (IZhO18_nicegift) C++17
7 / 100
754 ms 104268 KB
/*#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")*/

#include <bits/stdc++.h>
using namespace std;

#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define F(i,a,b) for (ll i=a;i<=b;i++)

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e6+40;
const ll mod=1000003 ;
const ll base=3e18;

/// you will be the best but now you just are trash
/// goal 2/7
ll a[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp", "r"))
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, k;
    cin>> n>> k;
    set<pll> st;
    for (int i=1;i<=n;i++)
    {
        cin>> a[i];
        st.insert(make_pair(a[i],i));
    }
    vector<pair<ll,vector<ll>>> ans;
    while (st.size()>=k)
    {
       ll val;
        auto it=st.end();
        ll len=k;
        vector<pll> vt1;
        vector<ll> vt ;
        while (len--)
        {
            it--;
            vt.pb((*it).ss);
            vt1.pb((*it));
            val=((*it).ff);
        }
        ans.pb(make_pair(val,vt));
        for (auto to:vt1)
        {
            pll p=to;
            st.erase(p);
            if (p.ff>val)
            {
                p.ff-=val;
                st.insert(p);
            }
        }
    }
    if (st.size())
    {
        cout <<-1;
        return 0;
    }
    cout <<ans.size()<<endl;
    for (auto p:ans)
    {
        cout <<p.ff<<" ";
        for (auto to:p.ss) cout <<to<<" ";
        cout <<endl;
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:45:21: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |     while (st.size()>=k)
      |            ~~~~~~~~~^~~
nicegift.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nicegift.cpp:64:13: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |             if (p.ff>val)
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 304 KB n=3
3 Correct 0 ms 324 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 332 KB n=4
6 Correct 1 ms 204 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 304 KB n=3
3 Correct 0 ms 324 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 332 KB n=4
6 Correct 1 ms 204 KB n=2
7 Correct 0 ms 328 KB n=5
8 Correct 0 ms 204 KB n=8
9 Incorrect 0 ms 332 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 304 KB n=3
3 Correct 0 ms 324 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 332 KB n=4
6 Correct 1 ms 204 KB n=2
7 Correct 0 ms 328 KB n=5
8 Correct 0 ms 204 KB n=8
9 Incorrect 0 ms 332 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 754 ms 104268 KB n=1000000
2 Correct 479 ms 58232 KB n=666666
3 Correct 284 ms 35268 KB n=400000
4 Incorrect 159 ms 25464 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB n=4
2 Correct 0 ms 304 KB n=3
3 Correct 0 ms 324 KB n=3
4 Correct 0 ms 204 KB n=4
5 Correct 0 ms 332 KB n=4
6 Correct 1 ms 204 KB n=2
7 Correct 0 ms 328 KB n=5
8 Correct 0 ms 204 KB n=8
9 Incorrect 0 ms 332 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -