結果

問題 No.3072 Speedrun Query
ユーザー tnakao0123
提出日時 2025-03-24 13:15:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 345 ms / 2,500 ms
コード長 1,391 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 41,856 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-24 13:15:10
合計ジャッジ時間 9,063 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   scanf("%d%d%d", &n, &ka, &kb);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:37:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |   for (int i = 0; i < ka; i++) scanf("%d", as + i);
      |                                ~~~~~^~~~~~~~~~~~~~
main.cpp:38:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |   for (int i = 0; i < kb; i++) scanf("%d", bs + i);
      |                                ~~~~~^~~~~~~~~~~~~~
main.cpp:50:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |   scanf("%d", &qn);
      |   ~~~~~^~~~~~~~~~~
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |     scanf("%d%d", &s, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 3072.cc: No.3072 Speedrun Query - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 300000;
const int INF = 1 << 30;
/* typedef */
/* global variables */
int as[MAX_N], bs[MAX_N];
/* subroutines */
int distv(int k, int vs[], int x) {
int i = lower_bound(vs, vs + k, x) - vs;
int d = INF;
if (i < k) d = min(d, vs[i] - x);
if (i > 0) d = min(d, x - vs[i - 1]);
return d;
}
/* main */
int main() {
int n, ka, kb;
scanf("%d%d%d", &n, &ka, &kb);
for (int i = 0; i < ka; i++) scanf("%d", as + i);
for (int i = 0; i < kb; i++) scanf("%d", bs + i);
int minab = INF;
for (int i = 0, j = 0; i < ka && j < kb;) {
minab = min(minab, abs(bs[j] - as[i]));
if (as[i] == bs[j]) break;
if (as[i] < bs[j]) i++;
else j++;
}
//printf(" minab = %d\n", minab);
int qn;
scanf("%d", &qn);
while (qn--) {
int s, t;
scanf("%d%d", &s, &t);
// (1) s->t
int d = abs(t - s);
// (2) s->(a)->t
int dsa = distv(ka, as, s), dta = distv(ka, as, t);
d = min(d, dsa + dta);
// (3) s->(b)->t
int dsb = distv(kb, bs, s), dtb = distv(kb, bs, t);
d = min(d, dsb + dtb);
// (4) s->(a)->(b)->t
d = min(d, dsa + minab + dtb);
// (5) s->(b)->(a)->t
d = min(d, dsb + minab + dta);
printf("%d\n", d);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0