Submission #70632

#TimeUsernameProblemLanguageResultExecution timeMemory
70632ics0503Toys (CEOI18_toy)C++17
100 / 100
1524 ms121520 KiB
#include<stdio.h> #include<vector> #include<map> #include<algorithm> using namespace std; int mn; map<int, int>M; vector<int>L[121212]; void get_ans(int n) { if (M.find(n) != M.end())return; int now = M[n] = ++mn; L[mn].push_back(n - 1); int i, j, w; for (i = 2; i*i <= n; i++) { if (n%i == 0) { get_ans(i), get_ans(n / i); w = M[i]; for (j = 0; j < L[w].size(); j++) L[now].push_back(L[w][j] + ((n / i) - 1)); w = M[n/i]; for (j = 0; j < L[w].size(); j++) L[now].push_back(L[w][j] + (i - 1)); } } sort(L[now].begin(),L[now].end()); L[now].erase(unique(L[now].begin(), L[now].end()), L[now].end()); } int main() { long long n, i, j; scanf("%d", &n); get_ans(n); int w = M[n]; printf("%d\n", L[w].size()); for (i = 0; i < L[w].size(); i++) { printf("%d ", L[w][i]); } return 0; }

Compilation message (stderr)

toy.cpp: In function 'void get_ans(int)':
toy.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (j = 0; j < L[w].size(); j++)
                ~~^~~~~~~~~~~~~
toy.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (j = 0; j < L[w].size(); j++)
                ~~^~~~~~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:29:35: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  long long n, i, j; scanf("%d", &n);
                                 ~~^
toy.cpp:32:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", L[w].size());
                 ~~~~~~~~~~~^
toy.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < L[w].size(); i++) {
              ~~^~~~~~~~~~~~~
toy.cpp:29:18: warning: unused variable 'j' [-Wunused-variable]
  long long n, i, j; scanf("%d", &n);
                  ^
toy.cpp:29:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  long long n, i, j; scanf("%d", &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...