Submission #405410

#TimeUsernameProblemLanguageResultExecution timeMemory
405410ollelToys (CEOI18_toy)C++14
100 / 100
4441 ms91012 KiB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back

int n;
map<int, vi> d;
map<int, set<int>> dp;


void getd(){
  set<int> divs;
  rep(i, 1, sqrt(n) + 4) {
    if (n % i == 0) {divs.insert(i); divs.insert(n / i);}
  }

  for (auto &i : divs) {
    dp.insert({i, {}});
    d.insert({i, vi(0)});
  }

  for (auto &i : divs){
    for (auto &j : divs){
      if (j % i == 0) {
        d[j].pb(i);
      }
    }
  }
}

set<int> get(int x) {
  if (!(dp[x].empty())) return dp[x];

  dp[x].insert(x - 1);
  for (auto &y : d[x]) {
    for (auto &k : get(x/y)) {
      dp[x].insert(k + y - 1);
    }
  }
  return dp[x];
}

int main(){
  cin >> n;
  getd();
  set<int> ans = get(n);
  cout << ans.size() << endl;
  for (auto &i : ans) cout << i << " "; cout<<endl;
}

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:54:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   54 |   for (auto &i : ans) cout << i << " "; cout<<endl;
      |   ^~~
toy.cpp:54:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   54 |   for (auto &i : ans) cout << i << " "; cout<<endl;
      |                                         ^~~~
#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...