QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#777184#4179. SuperGCDZyh_AKer30 28ms22944kbC++142.8kb2024-11-23 23:23:522024-11-23 23:23:54

Judging History

你现在查看的是最新测评结果

  • [2024-11-23 23:23:54]
  • 评测
  • 测评结果:30
  • 用时:28ms
  • 内存:22944kb
  • [2024-11-23 23:23:52]
  • 提交

answer

#include <bits/stdc++.h>
//#define endl '\n'
//#define ll long long
using namespace std;
string sa, sb;
vector <short> jian(vector <short> x, vector <short> y)
{
	vector <short> ret(x.size() + 1, 0);
	for (int i = 1; i < min(x.size(), y.size()); i++)
	{
		if (x[i] - y[i] < 0)
		{
			x[i + 1] --;
			ret[i] = x[i] + 10 - y[i];
		}
		else
		{
			ret[i] = x[i] - y[i];
		}
	}
	return ret;
}
vector <short> cheng(vector <short> y)
{
	for (short &v : y)
	{
		v *= 2;
	}
	for (int i = 0; i < y.size(); i ++)
	{
		if (i == y.size() - 1 && y[i] >= 10)y.push_back(0);
		y[i + 1] += y[i] / 10;
		y[i] %= 10;
	}
	return y;
}
vector <short> chu(vector <short> x, short y)
{
	vector <short> ret;
	reverse(x.begin(), x.end());
	short v = 0;
	for (int i = 0; i < x.size(); i++)
	{
		if (!x[i] && !v && ret.size())
		{
			ret.push_back(0);
			continue;
		}
		v = v * 10 + x[i];
		if (v < y)ret.push_back(0);
		else
		{
			ret.push_back(v / y);
			v %= y;
		}
	}
	reverse(ret.begin(), ret.end());
	return ret;
}
bool small(vector <short> x, vector <short> y)
{
	reverse(x.begin(), x.end());
	reverse(y.begin(), y.end());
	string a, b;
	bool flag = false;
	for (int v : x)
	{
		if (flag || v)
		{
			flag = true;
			a.push_back(v + '0');
		}
	}
	flag = false;
	for (int v : y)
	{
		if (flag || v)
		{
			flag = true;
			b.push_back(v + '0');
		}
	}
	if (a.size() != b.size())return a.size() < b.size();
	else return a < b;
}
bool same(vector <short> x, vector <short> y)
{
	reverse(x.begin(), x.end());
	reverse(y.begin(), y.end());
	string a, b;
	bool flag = false;
	for (int v : x)
	{
		if (flag || v)
		{
			flag = true;
			a.push_back(v + '0');
		}
	}
	flag = false;
	for (int v : y)
	{
		if (flag || v)
		{
			flag = true;
			b.push_back(v + '0');
		}
	}
	return a == b;
}
vector <short> gcd(vector <short> a, vector <short> b)
{
	/*for (int i = 0; i < a.size(); i++)
		cout << a[i];
	cout << '\n';
	for (int i = 0; i < b.size(); i++)
		cout << b[i];
	cout << '\n';*/
	
	if (same(a, b))return a;
	else if (small(a, b)) return gcd(b, a);
	else if (a[1] % 2 == 0)
	{
		if (b[1] % 2 == 0)return cheng(gcd(chu(a, 2), chu(b, 2)));
		else return gcd(chu(a, 2), b);
	}
	else
	{
		if (b[1] % 2 == 0)return gcd(a, chu(b, 2));
		else return gcd(b, jian(a, b));
	}
}
int main()
{
	cin >> sa >> sb;
	vector <short> a(sa.size() + 1, 0);
	vector <short> b(sb.size() + 1, 0);
	for (int i = 0; i < sa.size(); i++)
	{
		a[sa.size() - i] = sa[i] - '0';
	}
	for (int i = 0; i < sb.size(); i++)
	{
		b[sb.size() - i] = sb[i] - '0';
	}
	vector <short> ans = gcd(a, b);
	reverse(ans.begin(), ans.end());
	ans.pop_back();
	bool flag = false;
	for (short x : ans)
	{
		if (x)flag = true;
		if (flag)cout << x;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 3836kb

input:

303033313591075494
466190570495733098

output:

62

result:

ok single line: '62'

Test #2:

score: 10
Accepted
time: 1ms
memory: 3648kb

input:

190947157244078666
634393608212792604

output:

46

result:

ok single line: '46'

Test #3:

score: 10
Accepted
time: 0ms
memory: 4640kb

input:

199734196228248887143452846336216962396323549856606482510660322599185490399357014777415360
482740891081532863235252291287425183197871658543514954073799496241634027613422576247188928

output:

350061248

result:

ok single line: '350061248'

Test #4:

score: 0
Wrong Answer
time: 28ms
memory: 22944kb

input:

183330767411949030985862327225441800386783201839954504742142344755697285545807839407893798440890335967106348646929303985665660707924120177902995612369404814440942838389303914023526786650300947071074080170532919161238477816684009809075974510858670795431746101620710616868364568522793797755354200219217...

output:

10

result:

wrong answer 1st lines differ - expected: '334784898627130', found: '10'

Test #5:

score: 0
Time Limit Exceeded

input:

101831089736464399143060421150931505949296457606509649175290655102429362890544008403583428159395913224389186118660441269524846213776017231533785416719256359998098806569485169053926720948277261656583947884765792389029784028512671773014273374815394069659203077966532770450239860799156184559694965356610...

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

206084286422505443493745813605851515585339943932239676146502976708286259171775092445057450580919919107373298873601099209253478876999121084106594989394564013420809310725649494263827641368381199414163487439430507032609942818629229494087175200115593372679822704519958106988782000134869143913399604825114...

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

808775086199454465157246109523364645124686363902900509259096057193152812999636929165688319266971087373555178515670380483215036985476962847935562422071880235110589991587041113733916077203152704472122784283492837211906933405942858051204678226285925223005208512836148904480222183928800337968980616511239...

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

913732187099259936146355718606961540843493602279081369325802720961760870004837442568433528232068301158462458320552047968777372433023014853019520442573981697024700686711661072554099169918435161749740397748573567126381374498416794558638580958960030441432865388679397607503581421887869555092892309165698...

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

231524614707249828075117919330298797903894039507252288965542453746842972147081808338027502342373155500308392964563815088718160659107054175880054154963084401697276618310398429897170114931486068992962628904368333693652670199409663167334838015359042384558437888270250168710350280455415327982154758284090...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

268391667465419486677720159957735055735387308628283340123412870676171544950793618068639527310112353198784525569420423416155027283439104803782540686805146121323026574332777030527007687633190130228376547560362635599807657189482747824921211594404012844102307996470324294928169240933897729421947506732193...

output:


result: