Submission #267088

#TimeUsernameProblemLanguageResultExecution timeMemory
267088peuchToys (CEOI18_toy)C++17
59 / 100
5076 ms6168 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 2e4; int n; int cnt; int v[MAXN], qnt[MAXN]; vector<int> divisor; vector<int> ans; map<int, vector<int> > dp; void getDiv(int num); void bt(int cur, int val, int num); void calcDP(int num); int main(){ scanf("%d", &n); calcDP(n); sort(ans.begin(), ans.end()); printf("%lu\n", ans.size()); for(int i = 0; i < ans.size(); i++) printf("%d ", ans[i]); printf("\n"); } void getDiv(int num){ memset(v, 0, sizeof(v)); memset(qnt, 0, sizeof(qnt)); divisor.clear(); cnt = 0; int x = num; for(int i = 2; i * i <= n; i++){ if(x % i == 0){ v[++cnt] = i; while(x % i == 0) qnt[cnt]++, x /= i; } } bt(1, 1, num); } void calcDP(int num){ if(!dp[num].empty()){ ans = dp[num]; return; } getDiv(num); vector<int> aux = divisor; vector<int> ret; ret.push_back(num - 1); vector<int> aux1, aux2; map<int, bool> marc; for(int i = 0; i < aux.size(); i++){ calcDP(aux[i]); aux1 = ans; calcDP(num / aux[i]); aux2 = ans; for(int i1 = 0; i1 < aux1.size(); i1++){ for( int i2 = 0; i2 < aux2.size(); i2++){ if(marc[aux1[i1] + aux2[i2]]) continue; ret.push_back(aux1[i1] + aux2[i2]); marc[aux1[i1] + aux2[i2]] = 1; } } } ans = ret; dp[num] = ans; } void bt(int cur, int val, int num){ if(cur > cnt){ if(val == 1 || val == num) return; divisor.push_back(min(val, num / val)); return; } int aux = 1; for(int i = 0; i <= qnt[cur]; i++){ bt(cur + 1, val * aux, num); aux *= v[cur]; } }

Compilation message (stderr)

toy.cpp: In function 'int main()':
toy.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
toy.cpp: In function 'void calcDP(int)':
toy.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  for(int i = 0; i < aux.size(); i++){
      |                 ~~^~~~~~~~~~~~
toy.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i1 = 0; i1 < aux1.size(); i1++){
      |                   ~~~^~~~~~~~~~~~~
toy.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for( int i2 = 0; i2 < aux2.size(); i2++){
      |                     ~~~^~~~~~~~~~~~~
toy.cpp: In function 'int main()':
toy.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  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...