Submission #881301

# Submission time Handle Problem Language Result Execution time Memory
881301 2023-12-01T04:20:56 Z dimashhh Gift (IZhO18_nicegift) C++17
7 / 100
569 ms 192672 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 1;
#define int long long
int n,k;
ll a[N];
set<pair<ll,ll>> st;
vector<pair<vector<int>,int>> res(N * 3);
void test(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        st.insert({a[i],i});
    }
    int it = 1;    
    while(!st.empty()){
        if((int)(it - 1) * k > 3e6||st.size() < k){
            cout << -1 << '\n';
            return;
        }
        vector<int> f;
        int oo;
        for(int i = 1;i <= k;i++){
            auto [x,y] = *st.rbegin();
            st.erase({x,y});
            oo = x;
            f.push_back(y);
        }
        res[it] = {f,oo};
        it++;
        for(auto j:f){
            a[j] -= oo;
            if(a[j]){
                st.insert({a[j],j});
            }
        }
    }
    cout << it - 1 << '\n';
    for(int f = 1;f < it;f++){
        cout << res[f].second << ' ';
        for(auto j:res[f].first)
            cout << j << ' ';
        cout << '\n';
    }
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T = 1;
    // cin >> T;
    while(T--)
        test();
}

Compilation message

nicegift.cpp: In function 'void test()':
nicegift.cpp:18:47: 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]
   18 |         if((int)(it - 1) * k > 3e6||st.size() < k){
      |                                     ~~~~~~~~~~^~~
nicegift.cpp: At global scope:
nicegift.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
nicegift.cpp: In function 'void test()':
nicegift.cpp:33:18: warning: 'oo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |             a[j] -= oo;
      |             ~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94232 KB n=4
2 Correct 22 ms 94300 KB n=3
3 Correct 22 ms 94296 KB n=3
4 Correct 20 ms 94296 KB n=4
5 Correct 21 ms 94296 KB n=4
6 Correct 23 ms 94296 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94232 KB n=4
2 Correct 22 ms 94300 KB n=3
3 Correct 22 ms 94296 KB n=3
4 Correct 20 ms 94296 KB n=4
5 Correct 21 ms 94296 KB n=4
6 Correct 23 ms 94296 KB n=2
7 Correct 21 ms 94300 KB n=5
8 Correct 21 ms 94296 KB n=8
9 Incorrect 20 ms 94296 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94232 KB n=4
2 Correct 22 ms 94300 KB n=3
3 Correct 22 ms 94296 KB n=3
4 Correct 20 ms 94296 KB n=4
5 Correct 21 ms 94296 KB n=4
6 Correct 23 ms 94296 KB n=2
7 Correct 21 ms 94300 KB n=5
8 Correct 21 ms 94296 KB n=8
9 Incorrect 20 ms 94296 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 569 ms 192672 KB n=1000000
2 Correct 393 ms 159296 KB n=666666
3 Correct 227 ms 132944 KB n=400000
4 Incorrect 134 ms 120256 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 94232 KB n=4
2 Correct 22 ms 94300 KB n=3
3 Correct 22 ms 94296 KB n=3
4 Correct 20 ms 94296 KB n=4
5 Correct 21 ms 94296 KB n=4
6 Correct 23 ms 94296 KB n=2
7 Correct 21 ms 94300 KB n=5
8 Correct 21 ms 94296 KB n=8
9 Incorrect 20 ms 94296 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -