結果
| 問題 |
No.998 Four Integers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-28 21:55:14 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,907 bytes |
| コンパイル時間 | 745 ms |
| コンパイル使用メモリ | 117,172 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-22 05:36:42 |
| 合計ジャッジ時間 | 1,617 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
ソースコード
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;
void scan(T...)(ref T args) {
auto line = readln.split;
foreach (ref arg; args) {
arg = line.front.to!(typeof(arg));
line.popFront;
}
assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
static if (is(typeof(arr[] = value))) {
arr[] = value;
}
else {
foreach (ref e; arr) {
fillAll(e, value);
}
}
}
bool chmin(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x > arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
bool chmax(T, U...)(ref T x, U args) {
bool isChanged;
foreach (arg; args) if (x < arg) {
x = arg;
isChanged = true;
}
return isChanged;
}
enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
void main() {
auto a = readln.split.to!(int[]).sort();
if (a[0] + 1 == a[1] && a[1] + 1 == a[2] && a[2] + 1 == a[3]) {
writeln("Yes");
}
else {
writeln("No");
}
}
struct FenwickTree(T) {
private {
int _size;
T[] _data;
}
this(int N) {
_size = N;
_data = new T[](_size + 1);
}
void add(int i, T x) {
i++;
while (i <= _size) {
_data[i] += x;
i += i & (-i);
}
}
T sum(int r) {
T res = 0;
while (r > 0) {
res += _data[r];
r -= r & (-r);
}
return res;
}
}
unittest {
auto ft = FenwickTree!(int)(10);
ft.add(0, 3);
ft.add(2, 4);
ft.add(5, 1);
assert(ft.sum(0) == 0);
assert(ft.sum(1) == 3);
assert(ft.sum(2) == 3);
assert(ft.sum(3) == 7);
assert(ft.sum(5) == 7);
assert(ft.sum(6) == 8);
}