제출 #246333

#제출 시각아이디문제언어결과실행 시간메모리
246333tonowakToys (CEOI18_toy)C++14
59 / 100
5066 ms3452 KiB
#include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin using LL = long long; // Poland #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) template<class T> int size(T &&x) { return int(x.size()); } template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) { out << '{'; for(auto it = x.begin(); it != x.end(); ++it) out << *it << (it == prev(x.end()) ? "" : ", "); return out << '}'; } void dump() {} template<class T, class... Args> void dump(T &&x, Args... args) { cerr << x << "; "; dump(args...); } #ifdef DEBUG struct Nl{~Nl(){cerr << '\n';}}; # define debug(x...) cerr << (strcmp(#x, "") ? #x ": " : ""), dump(x), Nl(), cerr << "" #else # define debug(...) 0 && cerr #endif mt19937_64 rng(0); int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } // end of templates int n; vector<int> curr_vec; int curr_mul = 1; set<int> answers; bool can_mul(int a, int b) { return a <= n / b and a * b <= n; } void backtrack() { debug(curr_mul, curr_vec); if(curr_mul == n) { answers.emplace(accumulate(curr_vec.begin(), curr_vec.end(), 0)); return; } // add new if(can_mul(curr_mul, 2)) { curr_mul *= 2; curr_vec.emplace_back(1); backtrack(); curr_mul /= 2; curr_vec.pop_back(); } // increase last number if(size(curr_vec) == 1 or (size(curr_vec) >= 2 and curr_vec.back() + 1 <= curr_vec.end()[-2])) if(can_mul(curr_mul / (curr_vec.back() + 1), curr_vec.back() + 2)) { curr_mul /= curr_vec.back() + 1; ++curr_vec.back(); curr_mul *= curr_vec.back() + 1; backtrack(); curr_mul /= curr_vec.back() + 1; --curr_vec.back(); curr_mul *= curr_vec.back() + 1; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; backtrack(); cout << size(answers) << '\n'; for(int a : answers) cout << a << ' '; cout << '\n'; }
#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...