結果
| 問題 |
No.723 2つの数の和
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2018-08-04 21:42:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 1,298 bytes |
| コンパイル時間 | 718 ms |
| コンパイル使用メモリ | 86,688 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 17:57:20 |
| 合計ジャッジ時間 | 1,713 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d%d", &n, &x);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:50:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | for (int i = 0; i < n; i++) scanf("%d", &as[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 723.cc: No.723 2つの数の和 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
/* typedef */
typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
/* global variables */
int as[MAX_N], bs[MAX_N], cs[MAX_N];
/* subroutines */
/* main */
int main() {
int n, x;
scanf("%d%d", &n, &x);
for (int i = 0; i < n; i++) scanf("%d", &as[i]);
sort(as, as + n);
int m = 0, pa = -1;
for (int i = 0; i < n; pa = as[i++]) {
if (pa != as[i])
bs[m] = as[i], cs[m] = 1, m++;
else
cs[m - 1]++;
}
//for (int i = 0; i < m; i++) printf("(%d,%d)", bs[i], cs[i]); putchar('\n');
ll cnt = 0;
int maxb = bs[m - 1];
for (int i = 0; i < m; i++) {
int d = x - bs[i];
if (d >= 0 && d <= maxb) {
int j = lower_bound(bs, bs + m, d) - bs;
if (j < m && d == bs[j])
cnt += (ll)cs[i] * cs[j];
}
}
printf("%lld\n", cnt);
return 0;
}
tnakao0123