結果
問題 | No.2821 A[i] ← 2A[j] - A[i] |
ユーザー |
![]() |
提出日時 | 2024-07-29 16:46:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 942 bytes |
コンパイル時間 | 413 ms |
コンパイル使用メモリ | 55,296 KB |
最終ジャッジ日時 | 2025-02-23 19:25:45 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 WA * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:55:40: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=] 55 | for (int i = 0; i < n; i++) printf("%d\n", ds[i]); | ~^ ~~~~~ | | | | int ll {aka long long int} | %lld main.cpp:32:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:33:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | for (int i = 0; i < n; i++) scanf("%lld", as + i); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2821.cc: No.2821 A[i] 竊・2A[j] - A[i] - yukicoder */ #include<cstdio> #include<set> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 300000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; using sl = set<ll>; /* global variables */ ll as[MAX_N], ds[MAX_N]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", as + i); ll mind = LINF; sl bs; bs.insert(as[0]); for (int i = 1; i < n; i++) { auto [sit, f] = bs.insert(as[i]); if (f) { if (sit != bs.begin()) { auto sit0 = sit; sit0--; mind = min(mind, as[i] - *sit0); } auto sit1 = sit; sit1++; if (sit1 != bs.end()) { mind = min(mind, *sit1 - as[i]); } ds[i] = mind; } else ds[i] = ds[i - 1]; } for (int i = 0; i < n; i++) printf("%d\n", ds[i]); return 0; }