# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345529 | nicolaalexandra | Odd-even (IZhO11_oddeven) | C++14 | 2094 ms | 376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 500
#define BASE 1000
using namespace std;
int a[DIM],aux[DIM],sol[DIM],ans[DIM],st[DIM],dr[DIM],mid[DIM],unu[3],v[DIM];
char s[DIM];
int i;
void adunare (int a[], int b[], int c[]){
int m;
if (a[0] > b[0]){
m = a[0];
for (int i=b[0]+1;i<=m;i++)
b[i] = 0;
} else {
m = b[0];
for (int i=a[0]+1;i<=m;i++)
a[i] = 0;
}
int t = 0;
for (int i=1;i<=m;i++){
c[i] = a[i] + b[i] + t;
t = c[i] / BASE;
c[i] %= BASE;
}
c[0] = m;
while (t){
c[++c[0]] = t%BASE;
t /= BASE;
}
}
void inmultire (int a[], int b[], int c[]){
for (int i=1;i<=a[0] + b[0];i++)
c[i] = 0;
c[0] = a[0] + b[0] - 1;
for (int i=1;i<=a[0];i++)
for (int j=1;j<=b[0];j++)
c[i+j-1] += a[i] * b[j];
int t = 0;
for (int i=1;i<=c[0];i++){
c[i] += t;
t = c[i] / BASE;
c[i] %= BASE;
}
while (t){
c[++c[0]] = t%BASE;
t /= BASE;
}
}
void impartire (int a[], int b){
int r = 0;
for (int i=a[0];i>=1;i--){
r = r * BASE + a[i];
a[i] = r / b;
r %= b;
}
while (a[0] > 1 && !a[a[0]])
a[0]--;
}
void scadere (int a[], int b[]){ /// a - b
for (int i=b[0]+1;i<=a[0];i++)
b[i] = 0;
int t = 0;
for (int i=1;i<=a[0];i++){
a[i] = a[i] - (b[i] + t);
if (a[i] < 0)
t = 1;
else t = 0;
if (t)
a[i] += BASE;
}
while (a[0] > 1 && !a[a[0]])
a[0]--;
}
int compare (int a[], int b[]){ /// a <= b
if (a[0] < b[0])
return 1;
if (a[0] > b[0])
return 0;
for (int i=a[0];i>=1;i--){
if (a[i] < b[i])
return 1;
if (a[i] > b[i])
return 0;
}
return 2; /// egale
}
void copiere (int a[], int b[]){
for (int i=0;i<=b[0];i++)
a[i] = b[i];
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
/// dc iau tle:((
cin>>s+1;
int n = strlen (s+1);
for (i=1;i<=n;i++)
v[i] = s[i] - '0';
for (i=n;i>=1;i-=3){
int val;
if (i >= 2)
val = (v[i-2] * 10 + v[i-1])*10 + v[i];
else val = v[i];
a[++a[0]] = val;
}
if (n == 1 && a[1] == 1){
cout<<1;
return 0;
}
if (n == 1 && a[1] == 2){
cout<<2;
return 0;
}
if (n == 1 && a[1] == 3){
cout<<4;
return 0;
}
for (i=1;i<=n/2+1;i+=3){
if (i <= n/2-1)
dr[++dr[0]] = 999;
else {
if (i <= n/2)
dr[++dr[0]] = 99;
else
dr[++dr[0]] = 9;
}
}
st[0] = st[1] = 1;
//st[0] = st[1] = 1;
unu[0] = unu[1] = 1;
while (compare(st,dr)){
adunare (st,dr,mid);
impartire (mid,2);
inmultire (mid,mid,aux);
adunare (mid,aux,aux);
impartire (aux,2);
if (compare(aux,a) == 1){
copiere (sol,mid);
adunare (mid,unu,st);
/// st = mid+1;
} else { /// dr = mid-1;
copiere (dr,mid);
scadere (dr,unu);
}
}
adunare (a,a,ans);
scadere (ans,sol);
scadere (ans,unu);
cout<<ans[ans[0]];
for (i=ans[0]-1;i>=1;i--){
int x = ans[i], nr = 0;
if (!x) nr = 1;
while (x){
nr++;
x /= 10;
}
for (int j=nr+1;j<=3;j++)
cout<<0;
cout<<ans[i];
}
//for (i=ans[0];i;i--)
// cout<<ans[i];
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |