Submission #5164574


Source Code Expand

Copy
void main() {
	auto N = ri;
	auto A = readAs!(int[]);
	auto L = new int[](N);
	auto R = new int[](N);

	L.front = A.front;
	R.back = A.back;
	foreach(i; 1..N) {
		L[i] = gcd(L[i-1], A[i]);
	}
	foreach_reverse(i; 0..N-1) {
		R[i] = gcd(R[i+1], A[i]);
	}
	ulong res;
	foreach(i; 0..N) {
		if(i == 0) { res = R[1]; continue; }
		if(i == N-1) { res = max(res, L[N-2]); continue; }
		res = max(res, gcd(L[i-1], R[i+1]));
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Submission Info

Submission Time
Task C - GCD on Blackboard
User private_yusuke
Language D (DMD64 v2.070.1)
Score 300
Code Size 1479 Byte
Status AC
Exec Time 29 ms
Memory 4392 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 16
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB
testcase_01 AC 17 ms 3988 KB
testcase_02 AC 27 ms 4264 KB
testcase_03 AC 1 ms 256 KB
testcase_04 AC 29 ms 4296 KB
testcase_05 AC 13 ms 3580 KB
testcase_06 AC 27 ms 4392 KB
testcase_07 AC 1 ms 256 KB
testcase_08 AC 1 ms 256 KB
testcase_09 AC 21 ms 3872 KB
testcase_10 AC 23 ms 3800 KB
testcase_11 AC 22 ms 3844 KB
testcase_12 AC 2 ms 380 KB
testcase_13 AC 1 ms 256 KB