結果
| 問題 |
No.2803 Bocching Star
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-15 14:19:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 2,000 ms |
| コード長 | 851 bytes |
| コンパイル時間 | 587 ms |
| コンパイル使用メモリ | 47,104 KB |
| 最終ジャッジ日時 | 2025-02-23 15:46:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d%d", &n, &s);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:32:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | for (int i = 0; i < n; i++) scanf("%d", ps + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2803.cc: No.2803 Bocching Star - yukicoder
*/
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
using pii = pair<int,int>;
/* global variables */
int ps[MAX_N], as[MAX_N];
pii pis[MAX_N];
/* subroutines */
/* main */
int main() {
int n, s;
scanf("%d%d", &n, &s);
for (int i = 0; i < n; i++) scanf("%d", ps + i);
for (int i = 0; i < n; i++) pis[i] = {ps[i], i};
sort(pis, pis + n);
int m = 0;
for (int i = 0; i < n; i++)
if ((i == 0 || pis[i - 1].first + s < pis[i].first) &&
(i == n - 1 || pis[i].first + s < pis[i + 1].first))
as[m++] = pis[i].second;
sort(as, as + m);
printf("%d\n", m);
for (int i = 0; i < m; i++)
printf("%d%c", as[i] + 1, (i + 1 < m) ? ' ' : '\n');
return 0;
}
tnakao0123