RE了,怎么回事?(用vector写的)

P1249 最大乘积

``` #include<iostream> #include<vector> using namespace std; vector<int> res,partition; int n,num=1; int main() { cin>>n; if(n==1){ cout<<1<<endl<<1; return 0; } while(num*(num+3)/2<=n)num++; num--; for (int i = 1; i <= num; ++i) { partition.push_back(i+1); } n-=num*(num+3)/2; int pos=partition.size()-1; while(n>0){ partition.at(pos)++; pos--,n--; if(pos<0)pos=partition.size()-1; } res.push_back(1); for (int j:partition) { for(int &x:res)x*=j; int JIN,s=res.size()-1; for (int i = 0; i < s; ++i) { JIN=res.at(i)/10; res.at(i)%=10; res.at(i+1)+=JIN; } while(JIN){ JIN=res.at(s)/10; res.at(s)%=10; res.push_back(JIN); s++; } } for (int x:partition) { cout<<x<<' '; } cout<<endl; int pos2=res.size()-1; while(res.at(pos2)==0)pos2--; for(int i=pos2;i>=0;i--){ cout<<res.at(i); } return 0; } ```
by Hiusiudou @ 2022-12-25 12:08:42


|