結果
| 問題 |
No.723 2つの数の和
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-03 22:46:19 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 2,107 bytes |
| コンパイル時間 | 786 ms |
| コンパイル使用メモリ | 112,692 KB |
| 実行使用メモリ | 9,228 KB |
| 最終ジャッジ日時 | 2024-06-13 01:35:10 |
| 合計ジャッジ時間 | 2,370 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
alias Edge = Tuple!(int, "u", int, "v");
void main() {
int n, x;
scan(n, x);
auto a = readln.split.to!(int[]);
int[int] asc;
long ans;
foreach (i ; 0 .. n) {
if (a[i] in asc) {
ans += 2*asc[a[i]];
}
if (a[i]*2 == x) {
ans++;
}
if (x - a[i] in asc) {
asc[x-a[i]]++;
}
else {
asc[x-a[i]] = 1;
}
}
writeln(ans);
}
struct UnionFind {
private {
int _size;
int[] _parent;
}
this(int N)
in {
assert(N > 0);
}
body {
_size = N;
_parent = new int[](_size);
foreach (i ; 0 .. _size) {
_parent[i] = i;
}
}
int findRoot(int x)
in {
assert(0 <= x && x < _size);
}
body {
if (_parent[x] != x) {
_parent[x] = findRoot(_parent[x]);
}
return _parent[x];
}
bool same(int x, int y)
in {
assert(0 <= x && x < _size);
assert(0 <= y && y < _size);
}
body {
return findRoot(x) == findRoot(y);
}
void merge(int x, int y)
in {
assert(0 <= x && x < _size);
assert(0 <= y && y < _size);
}
body {
int u = findRoot(x);
int v = findRoot(y);
if (u == v) return;
_parent[v] = u;
}
}
void scan(T...)(ref T args) {
import std.stdio : readln;
import std.algorithm : splitter;
import std.conv : to;
import std.range.primitives;
auto line = readln().splitter();
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);
}
}
}