Submission #1041574


Source Code Expand

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORU(i,j,k) for(int i=(j);i<=(k);++i)
#define FORD(i,j,k) for(int i=(j);i>=(k);--i)

#define RDI(n) scanf("%d", &(n));
#define RDL(n) scanf("%lld", &(n));

using namespace std;

using lli = long long int;
using pll = pair<lli, lli>;

const long long int oo = 1000*1000*1000;

struct Coord
{
	int x, y;
	Coord(int x = 0, int y = 0) : x(x), y(y) {}
	Coord operator + (const Coord& droite) const
	{
		return Coord(x + droite.x, y + droite.y);
	}
};

struct AB
{
	int k;
	vector<lli> arbre;
	AB(int _k = 20, lli def = 0)
	{
		k = _k;
		FOR(i, 1 << k)
			arbre.push_back(i < (1 << (k-1)) ? 0LL : def);
		FORD(i, ((1 << (k-1)) - 1), 1)
			arbre[i] = arbre[i << 1] + arbre[(i << 1) ^ 1];
	}
	void set(int i, lli x)
	{
		int feuille = i + (1 << (k-1));
		arbre[feuille] = x;
		iset(feuille >> 1);
	}
	void iset(int noeud)
	{
		if(noeud)
		{
			arbre[noeud] = arbre[noeud << 1] + arbre[(noeud << 1)  ^ 1];
			iset(noeud >> 1);
		}
	}
	lli sum(int deb, int fin, int noeud = 1, int p = 0, int q = -1)
	{
		if(q < p)
			q = 1 << (k-1);
		if(deb <= p && q <= fin)
			return arbre[noeud];
		if(deb >= q || fin <= p)
			return 0LL;
		int mil = (p + q) / 2;
		return sum(deb, fin, noeud << 1, p, mil) + sum(deb, fin, (noeud << 1) ^ 1, mil, q);
	}
};

int main()
{
	lli a, b;
	scanf("%lld%lld", &a, &b);
	lli r = 1000*oo;
	if(0 <= a && a <= b)
		r = min(r, b - a);
	if(0 <= b && b <= a)
		r = min(r, 2 + a - b);
	if(a <= 0 && 0 <= b)
		r = min(r, 1 + abs(b + a));
	if(a <= b && b <= 0)
		r = min(r, b - a);
	if(b <= a && a <= 0)
		r = min(r, 2 + a - b);
	if(b <= 0 && 0 <= a)
		r = min(r, 1 + abs(b + a));
	printf("%lld\n", r);
	return 0;
}

Submission Info

Submission Time
Task A - Simple Calculator
User Akulen
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1906 Byte
Status AC
Exec Time 1 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:76:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &a, &b);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 14
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 128 KB
0_01.txt AC 1 ms 128 KB
0_02.txt AC 1 ms 128 KB
1_00.txt AC 1 ms 128 KB
1_01.txt AC 1 ms 128 KB
1_02.txt AC 1 ms 128 KB
1_03.txt AC 1 ms 128 KB
1_04.txt AC 1 ms 128 KB
1_05.txt AC 1 ms 128 KB
1_06.txt AC 1 ms 128 KB
1_07.txt AC 1 ms 128 KB
1_08.txt AC 1 ms 128 KB
1_09.txt AC 1 ms 128 KB
1_10.txt AC 1 ms 128 KB