結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-17 22:28:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 605 ms / 3,000 ms |
コード長 | 1,793 bytes |
コンパイル時間 | 1,300 ms |
コンパイル使用メモリ | 96,460 KB |
最終ジャッジ日時 | 2025-02-11 13:35:19 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:35:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | for (i=0; i<n; i++) scanf("%d", &as[i]); | ~~~~~^~~~~~~~~~~~~~ main.cpp:36:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | for (i=0; i<n; i++) scanf("%d", &bs[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<stdio.h>#include<string.h>#include<stdlib.h>#include <map>#include <vector>#include <queue>#include <deque>#include <set>#include <stack>#include <algorithm>#include <array>#include <unordered_set>#include <unordered_map>#include <string>using namespace std;bool rcmp(int a, int b) { return a>b; }typedef long long LL;typedef struct { int h, i; }RNode;int as[200004];int bs[200004];int cs[200004];class mypcmp {public:bool operator()(const RNode& a, const RNode& b) {return a.h<b.h;}};#define INF 0x7fffffffint main() {int n, i, h, mh, r, valid, t;scanf("%d", &n);for (i=0; i<n; i++) scanf("%d", &as[i]);for (i=0; i<n; i++) scanf("%d", &bs[i]);set<int> hs;for (i=0; i<n; i++) {if (as[i]>bs[i]) { t=as[i]; as[i]=bs[i]; bs[i]=t; }cs[i]=(as[i]+bs[i])/2;hs.insert(as[i]);hs.insert(bs[i]);hs.insert(cs[i]);}priority_queue<RNode, vector<RNode>, mypcmp> q;r = INF;mh= INF;for (i=0; i<n; i++) {q.push({bs[i], i});mh=min(mh, bs[i]);}for (auto it = hs.rbegin(); it!=hs.rend(); it++) {h = *it;valid=1;while(!q.empty()) {auto x = q.top();if (x.h>h) {q.pop();i=x.i;if (cs[i]<=h) {q.push({cs[i], i});mh = min(mh, cs[i]);} else if (as[i]<=h) {q.push({as[i], i});mh = min(mh, as[i]);} else {valid=0;break;}} else break;}if (valid==0) break;r = min(r, h-mh);}printf("%d\n", r);return 0;}