Submission #643342

# Submission time Handle Problem Language Result Execution time Memory
643342 2022-09-21T18:44:03 Z Matteo_Verz Present (RMI21_present) C++17
8 / 100
797 ms 86236 KB
#include <bits/stdc++.h>
#ifdef BLAT
   #include "debug/debug.hpp"
#else
   #define debug(x...)
#endif

using namespace std;

void generateNextSet(vector <int> &set) {
    int lastdeleted = 0;
    while (true) {
        if (set.empty() || set.back() > lastdeleted + 1) {
            set.push_back(lastdeleted + 1);
            break;
        }
        lastdeleted = set.back();
        set.pop_back();
    }

    long long gcd = 0;
    for (int i = 0; i < set.size(); i++)
        for (int j = i + 1; j < set.size(); j++)
            gcd |= (1 << (__gcd(set[i], set[j])));
    

    for (int i = set.back() - 1; i >= 1; i--)
        if (gcd & (1 << i))
            set.push_back(i);
}

void printSet(vector <int> &set, int setidx) {
    reverse(set.begin(), set.end());
    // cout << "S" << setidx << " = {";
    cout << set.size() << ' ';
    for (int i = 0; i < set.size(); i++)
        cout << set[i] << ' ';
    cout << '\n';
    reverse(set.begin(), set.end());
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    vector <vector <int>> sets = {{0}};
    vector <int> set = {1};
    for (int i = 1; i <= 1000000; i++) {
        sets.push_back(set);
        generateNextSet(set);
    }

    int t;
    cin >> t;
    while (t--) {
        int k;
        cin >> k;
        if (k == 0) cout << 0 << '\n';
        else printSet(sets[k], k);
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void generateNextSet(std::vector<int>&)':
Main.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < set.size(); i++)
      |                     ~~^~~~~~~~~~~~
Main.cpp:23:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int j = i + 1; j < set.size(); j++)
      |                             ~~^~~~~~~~~~~~
Main.cpp: In function 'void printSet(std::vector<int>&, int)':
Main.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i < set.size(); i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 797 ms 85960 KB Output is correct
2 Correct 785 ms 85992 KB Output is correct
3 Correct 784 ms 86016 KB Output is correct
4 Correct 772 ms 86236 KB Output is correct
5 Correct 789 ms 86000 KB Output is correct
6 Correct 780 ms 86016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 797 ms 85960 KB Output is correct
2 Correct 785 ms 85992 KB Output is correct
3 Correct 784 ms 86016 KB Output is correct
4 Correct 772 ms 86236 KB Output is correct
5 Correct 789 ms 86000 KB Output is correct
6 Correct 780 ms 86016 KB Output is correct
7 Incorrect 780 ms 85964 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 797 ms 85960 KB Output is correct
2 Correct 785 ms 85992 KB Output is correct
3 Correct 784 ms 86016 KB Output is correct
4 Correct 772 ms 86236 KB Output is correct
5 Correct 789 ms 86000 KB Output is correct
6 Correct 780 ms 86016 KB Output is correct
7 Incorrect 780 ms 85964 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 797 ms 85960 KB Output is correct
2 Correct 785 ms 85992 KB Output is correct
3 Correct 784 ms 86016 KB Output is correct
4 Correct 772 ms 86236 KB Output is correct
5 Correct 789 ms 86000 KB Output is correct
6 Correct 780 ms 86016 KB Output is correct
7 Incorrect 780 ms 85964 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 797 ms 85960 KB Output is correct
2 Correct 785 ms 85992 KB Output is correct
3 Correct 784 ms 86016 KB Output is correct
4 Correct 772 ms 86236 KB Output is correct
5 Correct 789 ms 86000 KB Output is correct
6 Correct 780 ms 86016 KB Output is correct
7 Incorrect 780 ms 85964 KB Output isn't correct
8 Halted 0 ms 0 KB -