Submission #538915

#TimeUsernameProblemLanguageResultExecution timeMemory
538915ryangohcaToys (CEOI18_toy)C++17
79 / 100
889 ms262144 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define ti3 tuple<int, int, int>
#define ti4 tuple<int, int, int, int>
// This is like my secret account; yes it's like that  ~ Baek Jiheon, Feel Good (Secret Code)
using namespace std;
map<pii, int> off;
unordered_set<int> *dfs(int x, int s){
    unordered_set<int> * curr_set = new unordered_set<int>();
    curr_set->insert(x-1);
    off[{x, s}] = 0;
    for (int i = s; i*i<=x; i++){
        if (x%i != 0) continue;
        unordered_set<int> *child = dfs(x/i, i);
        if (child->size() <= curr_set->size()){
            int x1 = off[{x/i, i}];
            int p = off[{x, s}];
            for (auto j : *child){
                curr_set->insert(j + x1 + i-1 - p);
            }
        } else {
            swap(child, curr_set);
            swap(off[{x, s}], off[{x/i, i}]);
            off[{x, s}] += i - 1;
            int x1 = off[{x/i, i}];
            int p = off[{x, s}];
            for (auto j : *child){
                curr_set->insert(j + x1 - p);
            }
        }
    }
    return curr_set;
}
main(){
    int x; cin >> x;
    unordered_set<int> *ans = dfs(x, 2);
    vector<int> ot;
    int x2 = off[{x, 2}];
    for (auto i : *ans){
        ot.push_back(i + x2);
    }
    sort(ot.begin(), ot.end());
    cout << ot.size() << '\n';
    for (auto i : ot) cout << i << ' ';
}

Compilation message (stderr)

toy.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...