제출 #1070998

#제출 시각아이디문제언어결과실행 시간메모리
1070998YassirSalamaToys (CEOI18_toy)C++17
79 / 100
940 ms262144 KiB
    #include<bits/stdc++.h>
    using namespace std;
    #define pb push_back
    template<typename T> 
    ostream& operator << (ostream& out,vector<T> v){
        int i=0;
        for(auto x:v){
            out << x;
            i++;
            if(i==v.size()) break;
            out << " , ";
        }
        out << endl;
        return out;
    }
    template<typename T> 
    void dbg(const T& t){
        cout<<t<<"\n";
    }
    template<typename T,typename... Args>
    void dbg(const T& t,const Args&... args){
        cout<<t<<" , ";
        dbg(args...);
    }
    #define dbg(...) cout<<"("<<#__VA_ARGS__<<") : ";dbg(__VA_ARGS__);
    #define all(v) v.begin(),v.end()
    set<vector<int>> decomp;
    set<vector<int>> c;
    signed main(){
        int n;
        cin>>n;
        int x=n;
        vector<int> p;
        for(int i=2;;i++){
            if(i*i>n) break;
            while(n%i==0){
                p.pb(i);
                n/=i;
            }
        }
        if(n!=1) p.pb(n);
        // dbg(p)
        if(x==1){
            printf("1\n0");return 0;
        }
        if(p.size()==1){
            cout<<1<<endl;
            cout<<n-1<<endl;
            return 0;
        }
        decomp.insert({p[0]*p[1]});
        decomp.insert({p[0],p[1]});
        vector<int> t;
        for(int i=2;i<p.size();i++){
            c.clear();
            int pp=p[i];
            for(const auto &x:decomp){
                for(int j=0;j<x.size();j++){
                    t=x;
                    t[j]*=pp;
                    int k=j;
                    while(k+1<t.size()&&t[k]>t[k+1]){
                        swap(t[k],t[k+1]);
                        k++;
                    }
                    c.insert(t);
                }
                t=x;
                t.pb(pp);
                int j=t.size()-1;
                while(j-1>=0&&t[j]<t[j-1]){
                    swap(t[j],t[j-1]);
                    j--;
                }
                c.insert(t);
            }
            decomp=c;
        }
        vector<int> ans;
        for(auto &x:decomp){
            long long s=0;
            for(auto &y:x){
                s+=y-1;
            }
            ans.pb(s);
        }
        sort(all(ans));
        ans.erase(unique(all(ans)),ans.end());
        cout<<ans.size()<<"\n";
        for(auto x:ans){
            cout<<x<<" ";
        }
        cout<<"\n";
    }

컴파일 시 표준 에러 (stderr) 메시지

toy.cpp: In function 'int main()':
toy.cpp:54:22: 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=2;i<p.size();i++){
      |                     ~^~~~~~~~~
toy.cpp:58:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 for(int j=0;j<x.size();j++){
      |                             ~^~~~~~~~~
toy.cpp:62:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                     while(k+1<t.size()&&t[k]>t[k+1]){
      |                           ~~~^~~~~~~~~
#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...