F : maxmin
Diff : Hell(10)
Code :
#include <bits/stdc++.h>
using namespace std;
#define vec vector<long long>
class newInt {
public:
//setup
vec bits;bool sgn=false;
newInt() {bits.push_back(0);}
newInt(vec setupData) {bits = setupData;}
newInt(string a) {
int l=a.length();
if (l==0) bits.push_back(0);
for (int i=l-1;i>=0;i--) bits.push_back(a[i]-'0');
}
newInt(long long a) {
if (a==0) bits.push_back(0);
while (a!=0) {
bits.push_back(a%10);
a/=10;
}
}
//comput
inline newInt operator+ (newInt b) {
vec temp;
int size=max(bits.size(), b.bits.size());
temp.resize(size);
for (int i=0;i<size;i++) {temp[i]=(i<bits.size()?bits[i]:0)+(i<b.bits.size()?b.bits[i]:0);}
newInt res(temp);res.fix();
return res;
}
inline newInt operator+ (long long a) {
return *this+newInt(a);
}
newInt sub (newInt b) {
vec temp;
int size=max(bits.size(), b.bits.size());
temp.resize(size);
for (int i=0;i<size;i++) {temp[i]=(i<bits.size()?bits[i]:0)-(i<b.bits.size()?b.bits[i]:0);}
newInt res(temp);res.fix();
return res;
}
inline newInt operator- (newInt b) {
if (*this>b||*this==b) return this->sub(b);
newInt c=b.sub(*this);
c.sgn = true;
return c;
}
inline newInt operator- (long long a) {
return *this-newInt(a);
}
inline newInt operator* (newInt b) {
vec temp;
int size = bits.size()+b.bits.size();
temp.resize(size);
for (int i=0;i<bits.size();i++) {
for (int j=0;j<b.bits.size();j++) temp[i+j] += bits[i]*b.bits[j];
}
newInt res(temp);res.fix();
return res;
}
inline newInt operator* (long long a) {
newInt temp=*this;
for (int i=0;i<temp.bits.size();i++) temp.bits[i] *= a;
newInt res=temp;res.fix();
return res;
}
//compare
inline bool operator< (newInt b) {
if (bits.size()!=b.bits.size()) return bits.size()<b.bits.size();
for (int i=bits.size()-1;i>=0;i--) {
if (bits[i]!=b.bits[i]) return bits[i]<b.bits[i];
}
return false;
}
inline bool operator== (newInt b) {
if (bits.size()!=b.bits.size()) return false;
for (int i=bits.size()-1;i>=0;i--) {
if (bits[i]!=b.bits[i]) return false;
}
return true;
}
inline bool operator> (newInt b) {
if (bits.size()!=b.bits.size()) return bits.size()>b.bits.size();
for (int i=bits.size()-1;i>=0;i--) {
if (bits[i]!=b.bits[i]) return bits[i]>b.bits[i];
}
return false;
}
//to_console
void fix() {
while (exc()) {
int h=0;bits.resize(bits.size()+1);
for (int i=0;i<bits.size()-1;i++) {
h = bits[i]/10;
bits[i]%=10;
bits[i+1]+=h;
}
if (bits[bits.size()-1]==0) bits.resize(bits.size()-1);
}
}
bool exc() {
for (int i=0;i<bits.size();i++) {
if (bits[i]>=10) return true;
}
return false;
}
void pt() {
if (sgn) cout << '-';
if (bits.size()==1) {
cout << bits[0] << endl;
return ;
}
bool state=false;
for (int i=bits.size()-1;i>=0;i--) {
if (bits[i]!=0) state=true;
if (state) cout << bits[i];
}
if (!state) cout << 0;
cout << endl;
}
void pt_debug() {
for (int i=0;i<bits.size();i++) cout << bits[i] << ' ';
cout << endl;
}
//others
vec segment(int a, int b) {
vec res;
if (a>=b) {res.push_back(0);return res;}
if (a<0||a>=bits.size()||b<0||b>=bits.size()) {res.push_back(0);return res;}
for (int i=a;i<b;i++) res.push_back(bits[i]);
return bits;
}
};
int main() {
int l, c;cin >> l >> c;
string a;cin >> a;
newInt dp[l+1][l+1];
for (int i=1;i<=l;i++) dp[i][0] = newInt(a.substr(0, i));
for (int i=2;i<=l;i++) {
for (int j=1;j<=i-1;j++) {
//if (j==0) {dp[i][j] = newInt(a.substr(0, i));continue;}
dp[i][j] = newInt(0);
for (int k=j;k<i;k++) {
if (dp[i][j]<dp[k][j-1]*newInt(a.substr(k, i-k))) dp[i][j] = dp[k][j-1]*newInt(a.substr(k, i-k));
}
}
}
newInt maxv(0);
for (int i=1;i<=l;i++) {
if (maxv<dp[l][i]) maxv = dp[l][i];
}
dp[l][c].pt();
return 0;
}
Comment :
Before : (leave now)
A few minutes later : A = ?
Last : Oh!