Submission #1068275

# Submission time Handle Problem Language Result Execution time Memory
1068275 2024-08-21T09:01:59 Z cpdreamer Toys (CEOI18_toy) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define F first
#define S second
#define P pair
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7

void file(){
    freopen("input.txt.txt","r",stdin);
    freopen("output.txt.txt","w",stdout);
}

void solve() {
    int n;
    cin>>n;
    V<int>factor;
    bool prime[n+1];
    prime[1]=false;
    for(int i=2;i<=n;i++){
        prime[i]=true;
        for(int j=2;j<i;j++){
            if(i%j==0) {
                prime[i] = false;
                break;
            }
        }
    }
    V<int>primes;
    for(int i=2;i<=n;++i){
        if(prime[i])
            primes.pb(i);
    }
    int p=0;
    while(n>1){
        if(n%primes[p]==0){
            n/=primes[p];
            factor.pb(primes[p]);
        }
        else
            p++;
    }
    set<V<int>>st;
    st.insert({factor[0]});
    for(int i=1;i<factor.size();i++) {
        set<V<int>>st1;
        for (auto &u: st) {
            for (int j=0;j<u.size();j++) {
                V<int>v=u;
                v[j]*=factor[i];
                sort(all(v));
                st1.insert(v);
            }
            V<int>v=u;
            v.pb(factor[i]);
            sort(all(v));
            st1.insert(v);
        }
        st=st1;
    }
    V<int>ans;
    for(auto u:st) {
        int c = 0;
        for (auto x: u) {
            c += x - 1;
        }
        ans.pb(c);
    }
    sort(all(ans));
    auto it=unique(all(ans));
    ans.resize(distance(ans.begin(),it));
    cout<<ans.size()<<endl;
    for(auto u:ans)
        cout<<u<<" ";
    cout<<endl;
}

int main(){
    //file();
    solve();
}

Compilation message

toy.cpp: In function 'void solve()':
toy.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=1;i<factor.size();i++) {
      |                 ~^~~~~~~~~~~~~~
toy.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |             for (int j=0;j<u.size();j++) {
      |                          ~^~~~~~~~~
toy.cpp: In function 'void file()':
toy.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen("input.txt.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen("output.txt.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toy.cpp: At global scope:
toy.cpp:15:12: warning: 'called' defined but not used [-Wunused-variable]
   15 | static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7
      |            ^~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -