Submission #1004673


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }

int main() {
	int A; int B; int C; int D;
	while(~scanf("%d%d%d%d", &A, &B, &C, &D)) {
		int X = abs(A - C), Y = abs(B - D);
		int g = gcd(X, Y);
		int ans = (X / g + Y / g - 1) * g;
		printf("%d\n", ans);
	}
	return 0;
}

Submission Info

Submission Time
Task E - Segment on Grid Paper
User anta
Language C++14 (GCC 5.4.1)
Score 100
Code Size 912 Byte
Status AC
Exec Time 3 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt
Case Name Status Exec Time Memory
sample_01.txt AC 3 ms 256 KB
sample_02.txt AC 3 ms 256 KB
subtask1_01.txt AC 2 ms 256 KB
subtask1_02.txt AC 3 ms 256 KB
subtask1_03.txt AC 3 ms 256 KB
subtask1_04.txt AC 3 ms 256 KB
subtask1_05.txt AC 3 ms 256 KB
subtask1_06.txt AC 3 ms 256 KB
subtask1_07.txt AC 3 ms 256 KB
subtask1_08.txt AC 2 ms 256 KB
subtask1_09.txt AC 2 ms 256 KB
subtask1_10.txt AC 3 ms 256 KB
subtask1_11.txt AC 3 ms 256 KB
subtask1_12.txt AC 3 ms 256 KB
subtask1_13.txt AC 3 ms 256 KB
subtask1_14.txt AC 2 ms 256 KB
subtask1_15.txt AC 2 ms 256 KB
subtask1_16.txt AC 3 ms 256 KB
subtask1_17.txt AC 3 ms 256 KB
subtask1_18.txt AC 3 ms 256 KB
subtask1_19.txt AC 3 ms 256 KB