# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91686 | SamAnd | 홀-짝 수열 (IZhO11_oddeven) | C++17 | 49 ms | 504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma comment(linker,"/STACK:200000000")
#define _CRT_SECURE_NO_WARNINGS
#define mp make_pair
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <cstring>
void fp();
void sp();
using namespace std;
struct ban
{
vector<short> x;
};
bool operator<(const ban& a,const ban& b)
{
if(a.x.size()<b.x.size())
return true;
if(a.x.size()>b.x.size())
return false;
for(int i=0;i<a.x.size();++i)
{
if(a.x[i]<b.x[i])
return true;
if(a.x[i]>b.x[i])
return false;
}
return false;
}
bool operator==(const ban& a,const ban& b)
{
if(a.x.size()!=b.x.size())
return false;
for(int i=0;i<a.x.size();++i)
if(a.x[i]!=b.x[i])
return false;
return true;
}
bool operator>(const ban& a,const ban& b)
{
if(!(a<b) && !(a==b))
return true;
return false;
}
ban operator+(const ban& q,const ban& p)
{
ban a=q,b=p;
reverse(a.x.begin(),a.x.end());
reverse(b.x.begin(),b.x.end());
while(a.x.size()!=b.x.size())
{
if(a.x.size()<b.x.size())
a.x.push_back(0);
else
b.x.push_back(0);
}
int n=a.x.size();
ban res;
short x=0;
for(int i=0;i<n;++i)
{
x+=a.x[i];
x+=b.x[i];
res.x.push_back(x%10);
x/=10;
}
if(x)
res.x.push_back(x);
reverse(res.x.begin(),res.x.end());
return res;
}
ban operator-(const ban& p,const ban& q)
{
ban a=p,b=q;
reverse(a.x.begin(),a.x.end());
reverse(b.x.begin(),b.x.end());
while(a.x.size()!=b.x.size())
{
if(a.x.size()<b.x.size())
a.x.push_back(0);
else
b.x.push_back(0);
}
int n=a.x.size();
ban res;
for(int i=0;i<n;++i)
{
if(a.x[i]-b.x[i]>=0)
res.x.push_back(a.x[i]-b.x[i]);
else
{
a.x[i]+=10;
a.x[i+1]--;
res.x.push_back(a.x[i]-b.x[i]);
}
}
while(1)
{
if(res.x.empty())
break;
if(res.x.back())
break;
res.x.pop_back();
}
reverse(res.x.begin(),res.x.end());
return res;
}
ban operator*(const ban& a,const ban& b)
{
ban res;
int n=a.x.size();
for(int i=0;i<n;++i)
{
ban y;
for(int j=0;j<a.x[i];++j)
y=y+b;
for(int j=0;j<(n-i-1);++j)
y.x.push_back(0);
res=res+y;
}
return res;
}
ban operator/(const ban& a,const ban& b)
{
ban res;
short x=0;
for(int i=0;i<a.x.size();++i)
{
x*=10;
x+=a.x[i];
if(x>=2)
{
res.x.push_back(x/2);
x-=((x/2)*2);
}
else if(!res.x.empty())
res.x.push_back(0);
}
return res;
}
void tpel(ban a)
{
for(int i=0;i<a.x.size();++i)
cout<<a.x[i];
cout<<endl;
}
ban INF;
ban a1;
ban a2;
ban a4;
ban a;
void sol()
{
ban l=a1;
ban r=INF;
while(a4<(r-l))
{
if(!(l==a1))
cout<<"";
ban m=(r+l)/a2;
if((((m*m)+m)/a2)>a)
r=m;
else
l=m;
}
ban ans;
for(ban i=l;(i<r || i==r);i=i+a1)
{
ban m=i;
if((((m*m)+m)/a2)>a)
{
m=m-a1;
i=(((m*m)+m)/a2);
if(a==i)
ans=(m*m);
else
ans=(m*m)+(a-i-a1)*a2+a1;
break;
}
}
tpel(ans);
}
int main()
{
ios_base::sync_with_stdio(false);
//fp();
///////////////////////////////////
string s;
int n;
cin>>s;
n=s.size();
for(int i=0;i<n;++i)
a.x.push_back(s[i]-'0');
////////////////////////////
a1.x.push_back(1);
a2.x.push_back(2);
a4.x.push_back(4);
INF.x.push_back(1);
for(int i=0;i<50;++i)
INF.x.push_back(0);
///////////////////////////////////
sol();
sp();
return 0;
}
void fp()
{
#ifndef OLYMP
freopen("E.in","r",stdin);
freopen("E.out","w",stdout);
#endif
}
void sp()
{
#ifdef OLYMP
system("pause");
#endif
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |