답안 #699264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699264 2023-02-16T09:57:32 Z dattranxxx Toys (CEOI18_toy) C++11
0 / 100
4 ms 7252 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e5 + 5;

int n;
vector<int> divi[N], dp[N];

vector<pair<int, int>> adj[N];

int main() {
  cin.tie(0)->sync_with_stdio(0); cout.tie(0);
  cin >> n;
  
  if (n == 1) {
    cout << 1 << '\n' << 0;
    return 0;
  }
  
  vector<int> d;
  for (int i = 2; i * i <= n; ++i) if (n % i == 0) {
    d.emplace_back(i);
    if (i * i != n) d.emplace_back(n / i);
  }
  d.emplace_back(n);
  sort(d.begin(), d.end());
  
  for (int i = 0; i < d.size(); ++i) {
    for (int j = 0; j < i; ++j) if (d[i] % d[j] == 0) {
      int k = lower_bound(d.begin(), d.end(), d[i] / d[j]) - d.begin();
      adj[i].emplace_back(j, k);
    }
  }

  dp[d.size() - 1].emplace_back(0);
  
  for (int i = d.size() - 1; i; --i) {
    sort(dp[i].begin(), dp[i].end());
    dp[i].erase(unique(dp[i].begin(), dp[i].end()), dp[i].end());
    
    for (int s : dp[i]) {
      dp[d.size()].emplace_back(s + d[i] - 1);
    }
    
    for (auto& p : adj[i]) {
      int j, k; tie(j, k) = p;
      for (int s : dp[i]) {
        dp[k].emplace_back(s + d[j] - 1);
      }
    }
  }
  
  sort(dp[d.size()].begin(), dp[d.size()].end());
  dp[d.size()].erase(unique(dp[d.size()].begin(), dp[d.size()].end()), dp[d.size()].end());
  
  cout << dp[d.size()].size() << '\n';
  for (auto& x : dp[d.size()]) {
    cout << x << ' ';
  }
  
  
  
	return 0;
}

Compilation message

toy.cpp: In function 'int main()':
toy.cpp:29:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int i = 0; i < d.size(); ++i) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Incorrect 4 ms 7252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Incorrect 4 ms 7252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Incorrect 4 ms 7252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Incorrect 4 ms 7252 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Incorrect 4 ms 7252 KB Output isn't correct
3 Halted 0 ms 0 KB -