Submission #116194

# Submission time Handle Problem Language Result Execution time Memory
116194 2019-06-11T08:41:16 Z JohnTitor Toys (CEOI18_toy) C++11
0 / 100
2 ms 256 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Toys"
int n;

vector <pair <int, int>> v;
void factorize(int n){
    int i=2;
    while(i*i<=n){
        if(n%i==0){
            v.pb(mp(i, 0));
            while(n%i==0){
                v.back().second++;
                n/=i;
            }
        }
        i++;
    }
    if(n>1) v.pb(mp(n, 1));
}
vector <int> divisors;
void backtrack(int a, int b, int s){
    if(a==v.size()) divisors.pb(s);
    else{
        backtrack(a+1, 0, s);
        if(b<v[a].second) backtrack(a, b+1, s*v[a].first);
    }
}
map <int, vector <pair <int, int>>> f;
int cnt=0;
void caculate(int u){
    if(!f[u].empty()) return;
    vector <pair <int, bool>> temp;
    cnt++;
    temp.pb(mp(u-1, 0));
    temp.pb(mp(u, 1));
    for(int v: divisors) if((u%v==0)&&(u!=v)&&(v!=1)){
        caculate(u/v);
        for(auto x: f[u/v]){
            temp.pb(mp(x.first+v-1, 0));
            temp.pb(mp(x.second+v, 1));
        }
    }
    sort(temp.begin(), temp.end());
    int beg=temp[0].first;
    int cnt=0;
    for(auto x: temp){
        if(x.second){
            cnt--;
            if(cnt==0) f[u].pb(mp(beg, x.first-1));
        }
        else{
            cnt++;
            if(cnt==1) beg=x.first;
        }
    }
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    factorize(n);
    backtrack(0, 0, 1);
    bug(divisors.size());
    caculate(n);
    int ans=0;
    for(auto x: f[n]) ans+=x.second-x.first+1;
    writeln(ans);
    for(auto x: f[n]) FOR(i, x.first, x.second) write(i), putchar(' ');
}

Compilation message

toy.cpp: In function 'void backtrack(int, int, int)':
toy.cpp:39:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(a==v.size()) divisors.pb(s);
        ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -