Submission #20145843
Source Code Expand
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <variant>
#include <sstream>
#include <memory>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define sz(v) ((int)(v).size())
#define vec1d(x) vector<x>
#define vec2d(x) vector<vec1d(x)>
#define vec3d(x) vector<vec2d(x)>
#define vec4d(x) vector<vec3d(x)>
#define ivec1d(x, n, v) vec1d(x)(n, v)
#define ivec2d(x, n, m, v) vec2d(x)(n, ivec1d(x, m, v))
#define ivec3d(x, n, m, k, v) vec3d(x)(n, ivec2d(x, m, k, v))
#define ivec4d(x, n, m, k, l, v) vec4d(x)(n, ivec3d(x, m, k, l, v))
#ifdef LOCAL
#include "pretty_print.h"
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
#define nl "\n"
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }
auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; };
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
typedef pair<ll, ll> pll;
vector<pll> get(ll b, ll c) {
vector<pll> ret;
ll l = b - c / 2;
ll r = b;
ret.push_back({l, r});
if (c) {
if (c % 2 == 0) {
++l;
}
swap(l, r);
l = -l;
r = -r;
ret.push_back({l, r});
}
return ret;
}
int main(int /* argc */, const char** /* argv */)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
assert(freopen("i.txt", "r", stdin));
assert(freopen("o.txt", "w", stdout));
#endif
ll b, c;
while (cin >> b >> c) {
vector<pll> e;
vector<pll> fs = get(b, c);
vector<pll> sc = get(-b, c - 1);
e.insert(e.end(), all(fs));
e.insert(e.end(), all(sc));
sort(all(e));
ll ans = e[0].second - e[0].first + 1;
ll last = e[0].second;
for (int i = 1; i < sz(e); ++i) {
auto [l, r] = e[i];
if (l <= last) {
if (r > last) {
ans += r - last;
last = r;
}
} else {
ans += r - l + 1;
last = r;
}
}
cout << ans << nl;
}
#ifdef LOCAL
cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
#endif
return 0;
}
Submission Info
| Submission Time |
|
| Task |
B - -- - B |
| User |
aropan |
| Language |
C++ (GCC 9.2.1) |
| Score |
400 |
| Code Size |
3263 Byte |
| Status |
AC |
| Exec Time |
7 ms |
| Memory |
3660 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample.txt, sample_2.txt, sample_3.txt, sample_4.txt |
| All |
0_1.txt, 0_1000000000000000000.txt, 1000000000000000000_1.txt, 1000000000000000000_1000000000000000000.txt, 1312150450968415_354979173822804784.txt, 252509054433933443_74859962623690081.txt, 335408917861648769_779547116602436426.txt, 489647926824927166_979295853649854331.txt, 489647926824927166_979295853649854332.txt, 489647926824927166_979295853649854333.txt, 522842184971407772_585335723211047202.txt, 645762258982631929_269587449430302156.txt, 84324828731963978_148049062628894325.txt, 891351282707723854_349993004923078537.txt, sample.txt, sample_2.txt, sample_3.txt, sample_4.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 0_1.txt |
AC |
7 ms |
3512 KiB |
| 0_1000000000000000000.txt |
AC |
2 ms |
3568 KiB |
| 1000000000000000000_1.txt |
AC |
7 ms |
3648 KiB |
| 1000000000000000000_1000000000000000000.txt |
AC |
2 ms |
3624 KiB |
| 1312150450968415_354979173822804784.txt |
AC |
2 ms |
3572 KiB |
| 252509054433933443_74859962623690081.txt |
AC |
2 ms |
3464 KiB |
| 335408917861648769_779547116602436426.txt |
AC |
2 ms |
3624 KiB |
| 489647926824927166_979295853649854331.txt |
AC |
2 ms |
3576 KiB |
| 489647926824927166_979295853649854332.txt |
AC |
2 ms |
3624 KiB |
| 489647926824927166_979295853649854333.txt |
AC |
3 ms |
3616 KiB |
| 522842184971407772_585335723211047202.txt |
AC |
2 ms |
3500 KiB |
| 645762258982631929_269587449430302156.txt |
AC |
2 ms |
3620 KiB |
| 84324828731963978_148049062628894325.txt |
AC |
2 ms |
3572 KiB |
| 891351282707723854_349993004923078537.txt |
AC |
5 ms |
3464 KiB |
| sample.txt |
AC |
3 ms |
3560 KiB |
| sample_2.txt |
AC |
3 ms |
3624 KiB |
| sample_3.txt |
AC |
4 ms |
3660 KiB |
| sample_4.txt |
AC |
3 ms |
3616 KiB |